Properly create/update rows importing #486 (#503)

This commit is contained in:
Nabeel S
2020-01-16 10:40:42 -05:00
committed by GitHub
parent fa01c61677
commit c2f7c5e421
8 changed files with 40 additions and 33 deletions

View File

@@ -36,13 +36,11 @@ class FareImporter extends ImportExport
*/
public function import(array $row, $index): bool
{
// Try to add or update
$fare = Fare::firstOrNew([
'code' => $row['code'],
], $row);
try {
$fare->save();
// Try to add or update
$fare = Fare::updateOrCreate([
'code' => $row['code'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
return false;