Situation: Array index is right. And dd($row[5]) shows me "email address" from a record - work fine.
However on assigning it ($row[5]) to email field of the object, Laravel shows: ErrorException - Undefined offset: 5
Here is my code:
$file = $request->file('file');
$csvData = file_get_contents($file);
$rows = array_map('str_getcsv', explode("\n", $csvData));
foreach ($rows as $row) {
//dd($row[5]); // shows me email
$subscriber = new Subscriber;
$subscriber->email = $row[5]; // Shows: ErrorException - Undefined offset: 5
$subscriber->first_name = $row[3];
$subscriber->save();
}
Here's ddd($row);
array:7 [▼
0 => "1"
1 => "2019-02-27 01:01:52"
2 => "mailchimp"
3 => "Name"
4 => "Lastname"
5 => "[email protected]"
6 => "EN"
]
Any ideas what's wrong?
dd()only print first line.