How to use a custom policy for a custom resource page or disable authorization entirely?
Is it possible to use a custom policy for a custom resource page? Lets say I have a page to download files from an existing resource. I want to use a custom policy
download
for this resource. How can I manage access to the page? It seems like the model policies take precedence over the canAccess()
-method of the page. So the "normal" model policies deny access to the custom resource download page, because I can't define the download policy for this resource page.Solution:Jump to solution
Why is this even a Resource when you only have one custom page? Just create a single page
9 Replies
So the "normal" model policies deny access to the custom resource download page, because I can't define the download policy for this resource page.If you user cannot
viewAny
then the resource is not registering navigation. How does you policy restrict the access?
https://filamentphp.com/docs/3.x/panels/resources/getting-started#authorizationI don't think any other policies should apply to custom pages by default
I use the same resource in my "main" app panel that uses the default model policies. I setup an additional "guest" panel for unauthenticated users that can download files from a resource using some kind of magic link. For this I want to check if the URL contains a valid token instead of checking for any model policies (or use a custom policy for that check). For my custom page I don't need any navigation, breadcrumbs or whatsoever.
From my Resource class:
I encrounter a second issue with the
getPages()
-method if I omit the index page for the resource. Somehow the index page seems to be required?
Solution
Why is this even a Resource when you only have one custom page? Just create a single page
I created a custom page now. I was thinking about a resource page because I resolve a resource (eloquent model) from the magic link in the end and want to show a table with related data to that model. So I thought using a resource page for this would make sense.
But it seems like resource pages do not fit my use case
Resources are wrappers for classic CRUD: Create, Edit, List, Show
It doesn't make sense when it's a single page.
OK. So I can use a custom (non resource page) like described here: https://filamentphp.com/docs/3.x/panels/pages But still use Eloquent Models and Relationships within Form or Table?
Sure.
Alright thank you very much for your help!