Updated import validation functionality
This commit is contained in:
@@ -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'],
|
||||
|
||||
Reference in New Issue
Block a user