#Getting owner record in custom association action

3 messages · Page 1 of 1 (latest)

indigo arch
#

Hello all,

I have a book and story tables with a pivot table between the two. I have relationship manager to handle associating and dissociating books and stories. But the pivot table also has other data that needs to be entered when creating an association (order).
So I have overridden the form for the associate action like so:

         Tables\Actions\AssociateAction::make()
                    ->form([
                        Forms\Components\Select::make('story_id')->options(Story::query()->pluck('name', 'id'))->required()->label('Story'),
                        Forms\Components\TextInput::make('order')->numeric()->required()->label('Order'),
                    ]),

I am now trying to save all this stuff, but I cannot seem to retrieve the Book I'm currently editing inside the action. Is there a way to do so?

neon matrixBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

indigo arch
#

got it, I just used $this->getOwnerRecord()
and then attached the value with the extra values for the pivot table xD
Is there another way that would allow me to avoid overriding this behaviour, though ? I have many relationships with this kind of requirements...