I am just trying to learn this package and I am a simple model Team. Trying to import and export data from this model, this has exactly two fields name and description. When I am trying to import the teams.xlsx, it is showing error
Undefined offset: 1
I have followed this doc only difference is fields are name and description.
model method in my TeamsImport is
public function model(array $row)
{
//dd( $row[1] );
return new Team([
'name' => $row[0],
'description' => $row[1]
]);
}
return redirect('/')->with('failed', 'Some thing gone wrong!');
}
Expected behavior:
I think it should upload the file .
Actual behavior:
I have not idea, why it is getting undefined offset 1. while I am getting 'descripption' for dd($row[1]).
Any additional information, configuration or data that might be necessary to reproduce the issue.
This is the xls file, I am trying to import.
teams.xlsx
Try dump($row) and see what each row contains. It's probably not the first row, as dd() works for you.
I am getting the data inserted to my table correctly.But still getting this error. If I am using dump($row) I am getting output
array:2 [â–¼
0 => "name"
1 => "decription"
]
Perhaps it is because you have 3 sheets, and you get the error on the 2nd sheet.
@patrickbrouwers thank you, but Can you please suggest me some idea, how I should handle it?
Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html
Got it correct, thank you so much.
Great :)
Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html
thank you, this is really help me
Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html
I hope I'd have found this answer sooner. You're a genius! It worked!
Most helpful comment
Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html