Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrishanson's avatar

Custom Actions using existing policies

I am creating a custom action for sending emails, is there a filament way of linking this action to show/hide based on policy? I currently have the built in actions working with policies fine, would be nice if there was a simple, clean solution to do this, can't find anything in the docs.

Thanks

0 likes
3 replies
chrishanson's avatar

By the way, this does work but feels messy when I have the rest of these checks in the policy.

->visible(function(Message $message) {
                        return $message->status === MessageStatus::DRAFT;
                    })```
chrishanson's avatar

AI bot said to call a method that appears to not exist on the Action class, but changing it to this works so I can keep to using policies but still not ideal.

->visible(fn (Message $message) => auth()->user()->can('sendEmail', $message))
chrishanson's avatar
chrishanson
OP
Best Answer
Level 1

I found the solution to this, calling authorise on the custom action and passing in the model works.

Action::make('createMember')
                ->label('Create Member')
                ->slideOver()
                ->form(User::getEditForm(isChild: false))
                ->action(function(UserService $userService, array $data) {
                    $gym = Filament::getTenant();

                    $userService->createMember(
                        gym: $gym, 
                        data: ['member' => $data]
                    );
                })
                ->authorize('create', User::class)
                ->modalWidth(MaxWidth::Large),
1 like

Please or to participate in this conversation.