jeudi 12 septembre 2019

data does not enter at all when imported, .xls file format

when I import data with the .xls file format, all data cannot be entered, only the first data line is entered. is there something wrong with my script. please help me

when i typedd ($ data); all data can appear, but when I type dd ($ key); only 1 data that appears.

public function postDoImportData() {
        $path = Request::file('userfile')->getRealPath();
        $data = Excel::load($path, function($reader) {
        })->get();
        $json = json_decode($data);
        foreach ($json as $key) {
            $nama_divisi = $key->divisi;
            if($nama_divisi!=null) {
                $cek_divisi = DB::table('divisi')->where('namadivisi', $nama_divisi)->first();
                if ($cek_divisi!=null) {
                    $id_divisi = $cek_divisi->id;
                                        }else {
                                                $new_divisi['namadivisi'] = $nama_divisi;
                                                return redirect()->back()->with(
                                                ['message'=>'Data Gagal di Import!, Kemungkinan Anda Memasukan Nama Divisi Baru, Perbarui Dahulu Data Divisi Anda!','message_type'=>'warning']);
                                                }
                switch( $key->jeniskelamin) {
                                                case "L":$jeniskelamin = "Laki-laki"; break;
                                                case "P":$jeniskelamin = "Perempuan"; break;
                                                default:$jeniskelamin = "error"; break;
                                                }
                                            }
                $insert = [
                            'nip'           => $key->nip,
                            'id_divisi'     => $id_divisi,
                            'nama'          => $key->nama,
                            'jeniskelamin'  => $jeniskelamin,
                            'email'         => $key->email,
                            'password'      => Hash::make($key->password),
                            'no_hp'         => $key->no_hp
                            ];
                            $result = DB::table('user')->insert($insert);
                            return redirect()->back()->with(['message'=>'upload Success!','message_type'=>'success']);              
                }
            }

I want to import a lot of data, how can I import all my data. what is wrong with my script. help me fix it. I use laravel 5.4. thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ae2dAA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire