Skip to content

Commit

Permalink
refs #1734 Add try-catch to show the formatting error to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
burakcakirel committed Jan 28, 2021
1 parent 06eb498 commit a031a6e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/Abstracts/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

use App\Traits\Import as ImportHelper;
use App\Utilities\Date;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\SkipsOnError;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Validators\Failure;
use Illuminate\Support\Facades\Validator;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;

abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatchInserts, WithChunkReading, WithHeadingRow, WithMapping, WithValidation
Expand Down Expand Up @@ -45,7 +47,12 @@ public function map($row): array
continue;
}

$row[$date_field] = Date::parse(ExcelDate::excelToDateTimeObject($row[$date_field]))->format('Y-m-d H:i:s');
try {
$row[$date_field] = Date::parse(ExcelDate::excelToDateTimeObject($row[$date_field]))
->format('Y-m-d H:i:s');
} catch (InvalidFormatException | \Exception $e) {
Log::info($e->getMessage());
}
}

return $row;
Expand Down

0 comments on commit a031a6e

Please sign in to comment.