-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathImportCsv.php
46 lines (40 loc) · 1.02 KB
/
ImportCsv.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Coderflex\LaravelCsv\Jobs;
use Coderflex\LaravelCsv\Models\Import;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ImportCsv implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Batchable;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(
public Import $import,
public string $model,
public array $chunk,
public array $columns,
) {
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$affectedRows = $this->model::upsert(
$this->chunk,
['id'],
collect($this->columns)->diff(['id'])->keys()->toArray(),
);
$this->import->increment('processed_rows', $affectedRows);
}
}