Im using ToModel in my import and need to store the current row number.
How do i do that? :)
namespace App\Imports;
use App\User;
use Maatwebsite\Excel\Concerns\ToModel;
class UsersImport implements ToModel
{
public function model(array $row)
{
return new User([
'name' => $row[0],
'row_number' => '?????'
]);
}
}
@dalholm you can keep state in your import object.
class UsersImport implements ToModel
{
private $row = 0;
public function model(array $row)
{
return new User([
'name' => $row[0],
'row_number' => ++$this->row,
]);
}
}
@patrickbrouwers so simple, worked like a charm. Thanks! 馃憤
@dalholm you can keep state in your import object.
class UsersImport implements ToModel { private $row = 0; public function model(array $row) { return new User([ 'name' => $row[0], 'row_number' => ++$this->row, ]); } }
So, how do it at chunk reading?
@weiwait yes - any way of checking the row count in a chunked import?
@weiwait yes - any way of checking the row count in a chunked import?
I'm using Cache Dirve to record
current chunk
Most helpful comment
So, how do it at chunk reading?