Trying to import excel data to my mysql db and getting ErrorException Undefined offset: 0.
Tried using var_dump($row) to check the array of the row of the data. It looks off and not sure how to make the data shows nicely so that able to pass to db.
array(5) { ["a"]=> string(1) "B" ["white"]=> string(5) "Green" ["example1_at_gmailcom"]=> string(18) "example2@gmail.com" [60123456789]=> int(60162313142) [5]=> int(5) }
This is my excel data:
Model
public function model(array $row)
{
var_dump($row);
return new ContactList([
'first_name' => $row[0],
'last_name' => $row[1],
'email' => $row[2],
'phone' => $row[3],
'group_id' => $row[4],
]);
}
I already tried using replacing the $row[] with string and it works perfectly storing the data into my db.
Controller
if($request->hasFile('selected_file')){
$file = $request->file('selected_file');
Excel::import(new ContactListsImport, $file);
return redirect()->back()->with('success', 'Data saved successfully!');
}