F
Filament2w ago
Xavi

Importer action inside relationship

I have a Importer Action inside a relationship. How to get owner inside importer to create items? Owner must be Tier2 Model and it must import on Tier2Details Model this is my importaction code
public static function getColumns(): array
{
return [
ImportColumn::make('Url destino')
->label('destination_url')
->requiredMapping()
->rules(['required']),
ImportColumn::make('Anchor Url')
->label('link_url')
->rules(['required'])
->requiredMapping(),
ImportColumn::make('Anchor Keyword')
->label('anchor')
->rules(['required'])
->requiredMapping(),
ImportColumn::make('Fecha de realización')
->label('created_at')
->requiredMapping()
->rules(['required', 'date']),
ImportColumn::make('Follow/Nofollow')
->label('rel')
->requiredMapping()
->rules(['required']),
ImportColumn::make('Tipo')
->requiredMapping()
->rules(['required']),

];
}

public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your tier2 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;
}
public static function getColumns(): array
{
return [
ImportColumn::make('Url destino')
->label('destination_url')
->requiredMapping()
->rules(['required']),
ImportColumn::make('Anchor Url')
->label('link_url')
->rules(['required'])
->requiredMapping(),
ImportColumn::make('Anchor Keyword')
->label('anchor')
->rules(['required'])
->requiredMapping(),
ImportColumn::make('Fecha de realización')
->label('created_at')
->requiredMapping()
->rules(['required', 'date']),
ImportColumn::make('Follow/Nofollow')
->label('rel')
->requiredMapping()
->rules(['required']),
ImportColumn::make('Tipo')
->requiredMapping()
->rules(['required']),

];
}

public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your tier2 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;
}
Solution:
pass in livewire and use $this->livewire->parentRecord or ownerRecord if memory serves me correct
Jump to solution
2 Replies
Solution
toeknee
toeknee2w ago
pass in livewire and use $this->livewire->parentRecord or ownerRecord if memory serves me correct
Xavi
XaviOP2w ago
thanks @toeknee i use options property like this
Tables\Actions\ImportAction::make()
->label(__('Importar XLS'))
->importer(Tier2Importer::class)
->options(['tier2_id' => $this->getOwnerRecord()->getKey()]),
Tables\Actions\ImportAction::make()
->label(__('Importar XLS'))
->importer(Tier2Importer::class)
->options(['tier2_id' => $this->getOwnerRecord()->getKey()]),
Want results from more Discord servers?
Add your server