ViewAction on resource's table listing page

Hi, I have a model Estimate that has relationship to other model User. I want from ListEstimate page to have action that will open user info in a modal window (slideover). How to achive that? What I tried so far didn't work:
Tables\Actions\ViewAction::make('view-user')
->label('Show user')
->slideOver(true)
->record(fn ($record) => User::find($record->user_id));
Tables\Actions\ViewAction::make('view-user')
->label('Show user')
->slideOver(true)
->record(fn ($record) => User::find($record->user_id));
Solution:
I've manage to find the solution to my problem using mountUsing() method on an action by inspecting how ViewAction works in the Filament. This is my solution: ```php Tables\Actions\Action::make('view-linked-user') ->label('Show user')...
Jump to solution
4 Replies
tjodalv
tjodalv5mo ago
Oh yes and I also tried to use Filament\Actions\ViewAction instead of Filament\Tables\Actions\ViewAction but that didn't work either. If I use Filament\Tables\Actions\ViewAction, when clicking on, it opens view estimate page (I want to open user linked to estimate) and if I use Filament\Actions\ViewAction then nothing happens when clicking the button. Can anyone help please?
Tieme
Tieme5mo ago
you need modelcontent
Tables\Actions\ViewAction::make(uniqid())
->slideOver()
->modalContent(view('filament.pages.actions.advance'))
Tables\Actions\ViewAction::make(uniqid())
->slideOver()
->modalContent(view('filament.pages.actions.advance'))
For information about modal in action look at this page https://filamentphp.com/docs/3.x/actions/modals
tjodalv
tjodalv5mo ago
I do not want to create separate view as I already have User resource view page. I would like to display user view in a modal from Estimate listing page. If that make sense to you. I can use table's ViewAction to open User on the ListUsers.php page. I would like to open a modal to view user details on the ListEstimate.php page. The estimate is linked to a user.
Solution
tjodalv
tjodalv5mo ago
I've manage to find the solution to my problem using mountUsing() method on an action by inspecting how ViewAction works in the Filament. This is my solution:
Tables\Actions\Action::make('view-linked-user')
->label('Show user')
->slideOver(true)
->mountUsing(function (Form $form, Estimate $record) {
$user = User::find($record->user_id);
$form->model($user);
$form->operation('view');
$form->disabled(true);
$form->fill($user->toArray());
})
->form(function (Estimate $record): array {
return [...UserForm::fields()];
});
Tables\Actions\Action::make('view-linked-user')
->label('Show user')
->slideOver(true)
->mountUsing(function (Form $form, Estimate $record) {
$user = User::find($record->user_id);
$form->model($user);
$form->operation('view');
$form->disabled(true);
$form->fill($user->toArray());
})
->form(function (Estimate $record): array {
return [...UserForm::fields()];
});
In my form() method I am calling my custom class UserForm that define fields for this action and for my UserResource class.