when i want to running my import script, i have a trouble like this. i have replaced excel load() to excel import(), but this soltion doesn’t work. what should i do to slove this trouble?
when i want to running my import script, i have a trouble like this. i have replaced excel load() to excel import(), but this soltion doesn’t work. what should i do to slove this trouble?
public function postImport(Request $request)
{
// $this->validate($request, [
// 'file' => 'required|mimes:xls,xlsx'
// ]);
$path = $request->file('file')->getRealPath();
$data = Excel::load($path)->get();
// $data = Excel::toArray([],$path);
if($data->count() > 0)
{
foreach($data->toArray() as $key => $value)
{
foreach($value as $row)
{
$insert_data[] = array(
'nomorUrut' => $row[0],
'namaSupplier' => $row[1],
'singkatanSupplier' => $row[2],
'tipeSupplier' => $row[3],
'alamatSupplier' => $row[4],
'kodePosSupplier' => $row[5],
'noTelpSupplier' => $row[6],
'noFax' => $row[7],
'emailSupplier' => $row[8],
'contakSupplier' => $row[9],
'hp' => $row[10],
);
}
}
if(!empty($insert_data))
{
DB::table('uplSupplier')->insert($insert_data);
}
}
return back()->with('success', 'Excel Data Imported successfully.');
// }
2
Answers
I've put
InterfaceSupplier( as UplSupplierImport )
inappExports
. I have another trouble again, the trouble is "Array to string conversion". This is my newInterfaceSupplier( as UplSupplierImport )
that I've put in myapp/export
. For the new code of the controller was same with you code before:And this is the controller code:
Load method is removed from the current version of Laravel Exel. You can consider to do:
Create a import class:
Then:
If you want to use import method instead, reference https://docs.laravel-excel.com/3.1/imports/batch-inserts.html