63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports;
|
|
|
|
use App\Models\Locator;
|
|
use Filament\Actions\Imports\ImportColumn;
|
|
use Filament\Actions\Imports\Importer;
|
|
use Filament\Actions\Imports\Models\Import;
|
|
|
|
class LocatorImporter extends Importer
|
|
{
|
|
protected static ?string $model = Locator::class;
|
|
|
|
public static function getColumns(): array
|
|
{
|
|
return [
|
|
ImportColumn::make('locator_number')
|
|
->requiredMapping()
|
|
->exampleHeader('Locator Number')
|
|
->label('Locator Number')
|
|
->rules(['required']),
|
|
ImportColumn::make('locator_quantity')
|
|
->requiredMapping()
|
|
->numeric()
|
|
->exampleHeader('Locator Quantity')
|
|
->label('Locator Quantity')
|
|
->rules(['required', 'integer']),
|
|
ImportColumn::make('operator_id')
|
|
->requiredMapping()
|
|
->exampleHeader('Operator ID')
|
|
->label('Operator ID')
|
|
->rules(['required']),
|
|
ImportColumn::make('plant_id')
|
|
->requiredMapping()
|
|
->relationship('plant', 'name')
|
|
->exampleHeader('Plant')
|
|
->label('Plant')
|
|
->rules(['required']),
|
|
];
|
|
}
|
|
|
|
public function resolveRecord(): ?Locator
|
|
{
|
|
// return Locator::firstOrNew([
|
|
// // Update existing records, matching them by `$this->data['column_name']`
|
|
// 'email' => $this->data['email'],
|
|
// ]);
|
|
|
|
return new Locator();
|
|
}
|
|
|
|
public static function getCompletedNotificationBody(Import $import): string
|
|
{
|
|
$body = 'Your locator 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;
|
|
}
|
|
}
|