F
Filament2mo ago
Harvey

Action authorize() method not working

I have an action on a model called claim that is related to updaing a document. My action below uses a method on the DocumentPolicy to tell whether a user can upload a document. It no longer works like in v3, as the method downloadRequiredDocument never gets called, and I can not see the button etc. I can see that even though I include Document::class to the method it still tries to call a method on the ClaimPolicy (using ray). Is this a bug, or am I missing something? My action:
Action::make('download')
->iconButton()
->icon('heroicon-m-arrow-down-tray')
->tooltip('Download')
->authorize('downloadRequiredDocument', Document::class)
Action::make('download')
->iconButton()
->icon('heroicon-m-arrow-down-tray')
->tooltip('Download')
->authorize('downloadRequiredDocument', Document::class)
My DocumentPolicy method:
public function downloadRequiredDocument(User $user)
{
ray('downloadRequiredDocument called');
return $user->is_admin;
}
public function downloadRequiredDocument(User $user)
{
ray('downloadRequiredDocument called');
return $user->is_admin;
}
2 Replies
Harvey
HarveyOP2mo ago
The docs also don't mention using a different policy than the one for the current resource: https://filamentphp.com/docs/4.x/actions/overview#authorization-using-a-policy
Kikechi
Kikechi4w ago
@Harvey in your policy return Response::allow() or Response::deny() it will work automatically. For Boolean return you can use visible or hidden methods

Did you find this page helpful?