Passing data to custom pages
Hi everyone!
I need to build something like a custom resource, but using pages. It's a little more complicated, but imagine a model User that I display in a table first, with clickable entries that lead me to the corresponding EditPage and the prefilled form. So basically regular resource behavior. I managed to build the table and have the rows clickable with
->recordUrl(fn(User $record) => route('filament.admin.pages.user-edit', ['record' => $record->id]))
but I struggle with the form.
So my questions are:
- Is that the correct way of making the row clickable and passing the record?
- How do I set up the Edit Page correctly? Meaning getting the passed $record data and prefilling the form?
My current approach for the EditPage (based on ChatGPT) is:
This doesn't work though. I think I need to update the route so it accepts parameters, php artisan route:list
tells me, that unlike the regular resources, the route for my Edit Page doesn't accept a parameter. But I also don't know how to get this parameter inside the page.
I'm still kinda new to Laravel and Filament and I feel like I'm missing some basic knowledge, that I struggle to find in the docs. Where can I find these info in docs? Are there any tutorials to this specific topic?2 Replies
This is a syntax error and also not needed. You already have a user instance:
$this->record = User->find($record);
, but apart from that you are good. You can use ->formFill($this->record->toArray())
to save some lines.
tells me, that unlike the regular resources, the route for my Edit Page doesn't accept a parameterYou probably just need to set the
$slug
property.I've added
public static string|null $slug = 'user-edit';
But that didnt have any effect. The registered route still has no parameter and dd($record)
is empty and as long as this is the case, I can't even debug if my ->mount()
function is correct