F
Filament7mo ago
ericmp

How to get ownerRecord inside RecordImporter?

Lets setup 2 models. Event & People. The relationship is n to n. Inside the edit component of the event resource i added a relation manager - PeopleRelationManager. Now i started to configure the PeopleImporter so my users can import people into the event they are editing. The question is, can I somehow get the ownerRecord so i can attach the people imported to the current event? So far it works (the models are created), but the people arent attached to the event this is how it looks so far:
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class),
])
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class),
])
now i'm trying to pass in somehow the id of the event, but idk how to retrieve it inside the PeopleImporter class:
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class)->call([
'ownerRecord' => $this->getOwnerRecord(),
]),
])
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class)->call([
'ownerRecord' => $this->getOwnerRecord(),
]),
])
5 Replies
ericmp
ericmpOP7mo ago
bump
Vp
Vp7mo ago
I've never tried Import, but if this "PeopleImporter" is a livewire then you may get using mount()
ericmp
ericmpOP7mo ago
not sure if it is, its a class that extends vendor/filament/actions/src/Imports/Importer.php im just following the docs but not sure if what im trying to achieve is possible to achieve bump ^^
Dan Harrin
Dan Harrin7mo ago
have you tried passing it as an option? isnt there a section about importing relation managers
ericmp
ericmpOP7mo ago
sorry for not updating the question, like half an hour i discovered it! yeah now i do:
public function resolveRecord(): ?Contact
{
$contact = Contact::firstOrNew([
'email' => $this->data['email'],
]);

EventContact::updateOrCreate([
'contact_id' => $contact->id,
'event_id' => $this->options['ownerRecordId'],
]);

return $contact;
}
public function resolveRecord(): ?Contact
{
$contact = Contact::firstOrNew([
'email' => $this->data['email'],
]);

EventContact::updateOrCreate([
'contact_id' => $contact->id,
'event_id' => $this->options['ownerRecordId'],
]);

return $contact;
}
🙏 thanks
->options([
'ownerRecordId' => $this->getOwnerRecord()->id,
])
->options([
'ownerRecordId' => $this->getOwnerRecord()->id,
])
@Dan Harrin but im having an error and i dont undersand where it comes from - https://discord.com/channels/883083792112300104/1246023527019057193/1246023527019057193
Want results from more Discord servers?
Add your server