getFillable(); while (($row = fgetcsv($handle, 0, "~")) !== false) { unset($row[0]); // Remove the first empty column if present if (count($headers) === count($row)) { $data = array_combine($headers, $row); TempCustomer::updateOrCreate( ['customer_code' => $data['customer_code']], // key to find existing record $data // data to update or create ); } } 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); } } }