Clicking on a child record in a table to take you to that record - not edit

I have a form edit for a Parent record that has Child records under it. This works well. By default, when you click on a Child record in the table, it edits that record in a modal. I want to change that so that the page moves to the Child record in edit mode. I think something like this would work ->url("/childResourceName/childResourceNameId/edit") , but to do that I would need a value for the childResourceNameId and I don't know how to get that. Or am I trying to code this, and there's a way to configure the Filament table to do this? I've tried this example, but can't get the syntax correct:
TextEntry::make('title')
->url(fn (Post $record): string => route('posts.edit', ['post' => $record]))
TextEntry::make('title')
->url(fn (Post $record): string => route('posts.edit', ['post' => $record]))
Any advice on which way to attack this?
5 Replies
Stricks
StricksOP3mo ago
I did figure out this hack, but it's ugly: ->url(fn(Person $record): string => '/admin/people/' . $record->person_id . '/edit') This forms a URL off the people (the child) record.
Tonkawuck
Tonkawuck3mo ago
Generally if the child resource has an edit page the EditAction will direct to the page and not open a modal. Also, don't use routes like that. Use PersonResource::getUrl('edit', ['record' => $record]) Your closure will work in combination with the above code
Stricks
StricksOP3mo ago
@Tonkawuck Ah - thanks! I will try this. I'm confused as to where the PersonResource::getUrl('edit', ['record' => $record]) should go. Is this inside the ->url()? Seems wrong. Thanks for help on this. I'm been hacking at it all day.
Tonkawuck
Tonkawuck3mo ago
Yes, that function will return the route that you are currently constructing manually
Stricks
StricksOP3mo ago
Great, but my code looks like:
Tables\Columns\TextColumn::make('last_name')
->url("/admin/people/" . $person_id . "/edit"), // Like: /admin/people/1/edit
Tables\Columns\TextColumn::make('last_name')
->url("/admin/people/" . $person_id . "/edit"), // Like: /admin/people/1/edit
Does that go into the ->url()? If so, the $record variable isn't defined and errors out. Sorry to be a newbie, but I'm really having trouble learning how to pull data in Filamnet. So much is abstracted (which is wonderful) that it leaves me wondering. I've watched all the videos I can find, but I'm still not getting it. I think I got it! ->url(fn(Person $record): string => PersonResource::getUrl('edit', ['record' => $record])) I didn't have the PersonResource defined in my use statements. Thanks!
Want results from more Discord servers?
Add your server