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