getFillable(); Log::info('Headers: ' . implode(", ", $headers)); $rowCount = 0; while (($row = fgetcsv($handle, 0, "~")) !== false) { if (count($headers) === count($row)) { $data = array_combine($headers, $row); // Check if start_year_bal is empty and set it to 0 if so if (empty($data['start_year_bal']) || $data['start_year_bal'] ="" || $data['start_year_bal']== null) { $data['start_year_bal'] = 0; } if (empty($data['closure_date']) || $data['closure_date'] ="" || $data['closure_date']== null) { $data['closure_date'] = null; } try { if( $data['account_number'] !== 'account_number') { // Use firstOrNew instead of updateOrCreate $account = Account::firstOrNew(['account_number' => $data['account_number']]); $account->fill($data); $account->save(); } } catch (Exception $e) { Log::error('Error processing Account: ' . $e->getMessage()); } } } fclose($handle); } else { throw new Exception("Unable to open file: {$filePath}"); } } catch (Exception $e) { Log::error('Error in ProcessAccountDataJob: ' . $e->getMessage()); throw $e; } } }