Is there a way to skip the header row and start importing from the 2nd row?
Like:
class UsersImport implements ToModel
{
/**
* @param array $row
*
* @return User|null
*/
public function model(array $row)
{
return new User([
'name' => $row[0],
'email' => $row[1],
'password' => Hash::make($row[2]),
]);
}
}
But starting from the second row? So I don't have to worry about my header names, just the order of my columns.
I solved it with
class UsersImport implements ToModel, WithStartRow
{
...
/**
* @return int
*/
public function startRow(): int
{
return 2;
}
}
I know you've solved this already but there's a built-in way to do this: WithHeadingRow
I know you've solved this already but there's a built-in way to do this: WithHeadingRow
But if you use WithHeadingRow you cannot access row items by index
nice!
I know is closed, but if you use @lcardosozago 's method, don't forget to add:
use Maatwebsite\Excel\Concerns\WithStartRow;
Most helpful comment
I solved it with