diff --git a/app/Filament/Imports/LineImporter.php b/app/Filament/Imports/LineImporter.php index 12bc13b..6b9d532 100644 --- a/app/Filament/Imports/LineImporter.php +++ b/app/Filament/Imports/LineImporter.php @@ -3,9 +3,12 @@ namespace App\Filament\Imports; use App\Models\Line; +use App\Models\Plant; +use Filament\Actions\Imports\Exceptions\RowImportFailedException; use Filament\Actions\Imports\ImportColumn; use Filament\Actions\Imports\Importer; use Filament\Actions\Imports\Models\Import; +use Str; class LineImporter extends Importer { @@ -38,9 +41,19 @@ class LineImporter extends Importer public function resolveRecord(): ?Line { - $plant = \App\Models\Plant::where('name', $this->data['plant'])->first(); + $warnMsg = []; + $plant = Plant::where('name', $this->data['plant'])->first(); if (!$plant) { - return null; + $warnMsg[] = "Plant '" . $this->data['plant'] . "' not found"; + } + if (Str::length($this->data['name']) < 0) { + $warnMsg[] = "Line name not found"; + } + if (Str::length($this->data['type']) < 0) { + $warnMsg[] = "Line type not found"; + } + if (!empty($warnMsg)) { + throw new RowImportFailedException(implode(', ', $warnMsg)); } return Line::updateOrCreate([ 'name' => $this->data['name'],