Updated import validation functionality

This commit is contained in:
dhanabalan
2025-05-06 12:41:34 +05:30
parent daf81cd0c0
commit eb81eed835

View File

@@ -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'],