From ab52b7fe5f885b36ad8a9cc4338fec9af36bbcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Akg=C3=BCn?= Date: Thu, 8 Feb 2024 15:49:41 +0100 Subject: [PATCH] Remove reused table instance --- app/Jobs/ImportCSV.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Jobs/ImportCSV.php b/app/Jobs/ImportCSV.php index 358eb426..f95a51fe 100644 --- a/app/Jobs/ImportCSV.php +++ b/app/Jobs/ImportCSV.php @@ -77,10 +77,10 @@ public function handle(CSVImportReader $reader) // Log::info('$newArray', $newArray); - DB::transaction(function () use ($reader, $filepath, $mismatches_per_upload_user, $mismatch_attrs) { - - $reader->lines($filepath)->each(function ($mismatchLine) use ($mismatches_per_upload_user, $mismatch_attrs) { + DB::transaction(function () use ($reader, $filepath, $mismatch_attrs) { + $reader->lines($filepath)->each(function ($mismatchLine) use ($mismatch_attrs) { + $mismatches_per_upload_user = DB::table('mismatches'); $new_mismatch = Mismatch::make($mismatchLine); $collection = collect($new_mismatch->getAttributes()); @@ -92,9 +92,13 @@ public function handle(CSVImportReader $reader) } }); + // we add first because there might be duplicates already, so this might return more than 1 result $row_in_db = $mismatches_per_upload_user->select($mismatch_attrs)->where($newArray); $row_in_db_get = $row_in_db->get(); +// dump($newArray); +// dump($row_in_db->toSql()); +// dump($row_in_db_get->count()); Log::info("row_in_db: " . json_encode($row_in_db_get)); // var_dump($mismatches_per_upload_user->get()->count());