1
0
forked from poc/pds
Files
poc-pds1/app/Filament/Imports/PlantImporter.php
2025-04-23 12:29:49 +05:30

67 lines
2.2 KiB
PHP

<?php
namespace App\Filament\Imports;
use App\Models\Plant;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class PlantImporter extends Importer
{
protected static ?string $model = Plant::class;
public static function getColumns(): array
{
return [
ImportColumn::make('code')
->requiredMapping()
->numeric()
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->rules(['required']), //, 'integer'
ImportColumn::make('company')
->requiredMapping()
->exampleHeader('Company Name')
->example('C.R.I. Pumps Private Limited')
->label('Company Name')
->relationship(resolveUsing:'name')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->rules(['required']),
ImportColumn::make('address')
->requiredMapping()
->exampleHeader('Plant Address')
->example('7/51-A, Keeranatham Road, Saravanampatty, Coimbatore - 641035')
->label('Plant Address')
->rules(['required']),
];
}
public function resolveRecord(): ?Plant
{
// return Plant::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new Plant();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your plant import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
}
return $body;
}
}