Untitled
unknown
php
a year ago
929 B
14
Indexable
Excel::import(new VehiclesImport, $path);
======
class VehiclesImport implements ToCollection, WithHeadingRow, WithChunkReading, ShouldQueue
{
public function collection(Collection $rows)
{
$rows->chunk(1)->each(function ($chunk) {
ProcessVehicleRow::dispatch($chunk);
});
}
public function chunkSize(): int
{
return 3;
}
}
======
class ProcessVehicleRow implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $rows;
public function __construct(Collection $rows)
{
$this->rows = $rows;
}
public function handle()
{
foreach ($this->rows as $row) {
$this->processRow($row);
}
}
protected function processRow($row)
{
$nv = new Vehicle();
$nv->name = $row['title'];
.....
$nv->save();
}
}Editor is loading...
Leave a Comment