Created
March 9, 2024 10:36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Imports; | |
use App\Models\Participant; | |
use Filament\Actions\Imports\ImportColumn; | |
use Filament\Actions\Imports\Importer; | |
use Filament\Actions\Imports\Models\Import; | |
class Participant2Importer extends Importer | |
{ | |
protected static ?string $model = Participant::class; | |
public static function getColumns(): array | |
{ | |
return [ | |
ImportColumn::make('first') | |
->requiredMapping() | |
->rules(['required', 'max:255']), | |
]; | |
} | |
public function resolveRecord(): ?Participant | |
{ | |
// return Participant2::firstOrNew([ | |
// // Update existing records, matching them by `$this->data['column_name']` | |
// 'email' => $this->data['email'], | |
// ]); | |
return new Participant(); | |
} | |
public static function getCompletedNotificationBody(Import $import): string | |
{ | |
$body = 'Your participant2 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment