Help with resource actions

What I am trying to do: I Have a resource who has a user related to it. In the table i have a column to show who is this user. So, i want when I click the column show a modal with infos of the user(a view action) What I did: The column:
php TextColumn::make('executor.name')
->label('Executor')
->action(ViewAction::make('viewExecutioner')
->model(UserResource::getModel())
->record(fn (Execution $record): User => $record->executor)
->schema(UserResource::form(new Schema())->getComponents()) // ignore the schema, i do not build yet
)
->html()
->sortable(),
php TextColumn::make('executor.name')
->label('Executor')
->action(ViewAction::make('viewExecutioner')
->model(UserResource::getModel())
->record(fn (Execution $record): User => $record->executor)
->schema(UserResource::form(new Schema())->getComponents()) // ignore the schema, i do not build yet
)
->html()
->sortable(),
My issue/the error: The action try to get the table record(Execution) but i explicit say what model the action should use.
8 Replies
toeknee
toeknee2mo ago
On the column component you can add ->action(Define Filament Row Action Here) I believe. And possibly ->form() too.
Henrique
HenriqueOP2mo ago
Already do: The problem is the actions is trying to get the infos to the form in the wrong model.
No description
Henrique
HenriqueOP2mo ago
When i click the User, a exception is thrown because the infos that the form needs do not exists in the Execution Model, but i need the action to use the User Model But, i alredy told the action what model to use. And is not working :0 Obs: In this case is the V4 filament, the form method is deprecated
Dennis Koch
Dennis Koch2mo ago
The action try to get the table record(Execution) but i explicit say what model the action should use
You added ->record(fn (Execution <-- Which says: Give me an instance of Execution
Henrique
HenriqueOP2mo ago
but how i can say to the action the record i want. in this case the $execution->executioner, which is a user i want to open the User view modal for the $execution->executioner(User model related to the Execution)
toeknee
toeknee2mo ago
I would adjust the schema to be a state path tbh
->schema([Group::make('executor')->schema($schema)->statePath('executor')->relationship('executor')])
->schema([Group::make('executor')->schema($schema)->statePath('executor')->relationship('executor')])
free-typed but along those lines
Henrique
HenriqueOP2mo ago
This not worked. No one know a solution?
toeknee
toeknee2mo ago
It makes no sense why it wouldn’t work. Please provide the code you are using an are you using DD to ensure the record is as expected. What didn’t work?

Did you find this page helpful?