getFillable(); while (($row = fgetcsv($handle, 0, "~")) !== false) { if (count($headers) === count($row)) { $data = array_combine($headers, $row); try { if( $data['customer_code'] !== 'customer_code') { $customer = Customer::firstOrNew(['customer_code' => $data['customer_code']]); $customer->fill($data); $customer->save(); } }catch (Exception $e) { Log::error('Error processing Customer: ' . $e->getMessage()); } } } fclose($handle); } else { throw new Exception("Unable to open file: {$filePath}"); } return response()->json(['message' => 'Data Customer processing job has been successfully']); } catch (Exception $e) { return response()->json(['error' => $e->getMessage()], 500); } } }