Updated import validation functionality

This commit is contained in:
dhanabalan
2025-05-06 12:44:52 +05:30
parent b0149f6d61
commit 73df86f269

View File

@@ -3,10 +3,13 @@
namespace App\Filament\Imports;
use App\Models\Block;
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 Notification;
use Str;
class BlockImporter extends Importer
{
@@ -33,15 +36,23 @@ class BlockImporter extends Importer
public function resolveRecord(): ?Block
{
$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 not found";
// $warnMsg[] = "Plant '" . $this->data['plant'] . "' not found";
}
if (Str::length($this->data['name']) < 0) {
$warnMsg[] = "Block name not found";
}
if (!empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return Block::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
]
);
'name' => $this->data['name'],
'plant_id' => $plant->id
]);
// return Block::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],