Automatic Filament ViewAction on Livewire component

I have a Filament table on a Livewire component. I want to be able to jump to the following URL: /users?id=2 and have the component instantiate, but also to have the ViewAction for that specific user to fire. This should be possible, but I just don't know how to go about it.
4 Replies
Zen
Zen3mo ago
In th view page you can rewrite the mount() function and get $usserId = request()?->id; and get the record from the id or other wise you can just send to its argument using /users/2 instead.
pinpointzero
pinpointzeroOP3mo ago
public function mount(): void
{
// Fetch GET request parameters
$getParams = request()->query();
if (isset($getParams['id']) && is_numeric($getParams['id'])) {

Log::debug('ListUsers::mount() id: ' . $getParams['id']);
$this->userId = (int) $getParams['id'];
}
}
public function mount(): void
{
// Fetch GET request parameters
$getParams = request()->query();
if (isset($getParams['id']) && is_numeric($getParams['id'])) {

Log::debug('ListUsers::mount() id: ' . $getParams['id']);
$this->userId = (int) $getParams['id'];
}
}
Thank you for your response Zen. Yup, got that bit; but I can't get the view to automatically trigger to show it.
Action::make('show')
->formData($this->user->toArray())
->form(UsersSchema::form())
->label('View')
->icon('heroicon-s-eye')
->action(fn(User $record) => $this->showUser($record->id))
Action::make('show')
->formData($this->user->toArray())
->form(UsersSchema::form())
->label('View')
->icon('heroicon-s-eye')
->action(fn(User $record) => $this->showUser($record->id))
That's what the action looks like (minus the ->visible(false)
Zen Nitiruj
Zen Nitiruj3mo ago
Do you use Filament UserResource or just Livewire component?
pinpointzero
pinpointzeroOP3mo ago
It's just a Livewire component for this one. Tried a slightly different approach, and that's not working either.
Action::make(name: 'viewUser')
->form(form: UsersSchema::form())
->formData($this->userData)
->slideOver()
->call();
Action::make(name: 'viewUser')
->form(form: UsersSchema::form())
->formData($this->userData)
->slideOver()
->call();
Want results from more Discord servers?
Add your server