Description
I am getting the above error message as I am trying to import excel into db
View Code
*Here is my Controller*
👇👇
public function storeexcel(Request $request)
{
if($request->hasFile('file')){
$path = $request->file('file')->getRealPath();
$data = Excel::load($path)->get();
if($data->count()){
foreach ($data as $key => $value) {
$insert[] = [
'name' => $value->name,
'sex' => $value->sex,
'phone' => $value->phone,
'certificate_num' => $value->certificate_num,
'year' => $value->year,
'training_centre' => $value->training_centre,
'lga' => $value->lga,
'lga_code' => $value->lga_code,
'institution' => $value->institution,
'institution_code' => $value->institution_code,
//add all columns as per your requirement
];
}
if(!empty($insert)){
DB::table('certificates')->insert($insert);
return back()->with('success','Insert Record successfully.');
}
}
}
return back()->with('error','Please Check your file, Something is wrong .');
}
In version 3 the load method was removed, so if you still want to use the load method, downgrade your excel version.
Downgrade steps:
1. Delete the config/excel.php file first.
2. changing your composer.json file from "maatwebsite/excel": "^3.1", to "maatwebsite/excel": "~2.1.0"
3. composer update
For more details please visit the below link.
1 Like 0 Comments