add metod upsert and insert record in unique request
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Word;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImportCSVFileJob implements ShouldQueue
|
||||
@@ -34,19 +35,25 @@ class ImportCSVFileJob implements ShouldQueue
|
||||
];
|
||||
$fileStream = fopen($this->filepath, 'r');
|
||||
$skipHeader = true;
|
||||
$finalarray = array();
|
||||
while ($row = fgetcsv($fileStream)) {
|
||||
if ($skipHeader) {
|
||||
$skipHeader = false;
|
||||
continue;
|
||||
}
|
||||
Word::updateOrCreate(
|
||||
[
|
||||
'name' => $row[$mapping['name']],
|
||||
'translation' => $row[$mapping['translation']],
|
||||
]
|
||||
$finalarray[] = array(
|
||||
'name' => $row[$mapping['name']],
|
||||
'translation' => $row[$mapping['translation']],
|
||||
);
|
||||
//Word::updateOrCreate(
|
||||
// [
|
||||
// 'name' => $row[$mapping['name']],
|
||||
// 'translation' => $row[$mapping['translation']],
|
||||
// ]
|
||||
//);
|
||||
}
|
||||
fclose($fileStream);
|
||||
Storage::delete($this->filepath);
|
||||
DB::table('words')->upsert($finalarray, 'name', 'translation');
|
||||
//fclose($fileStream);
|
||||
//Storage::delete($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ return [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 1250,
|
||||
'retry_after' => 9000,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user