Authorization based on Resource Actions

Posted 4 months ago by pehbehbeh

We felt a bit limited with the existing canSee and canSeeWhen methods for authorization on nova fields.

We need to have field policies for each individual action of a resource on our Nova fields. We solved the problem with some field macros. With these two helpers you can do something like this:

        'index' => function () {
            return true;
        'create' => function () {
            return false;
    ], $this),

...or use a policy:

        'index' => 'indexPolicy',
        'create' => 'createPolicy',
    ], $this),

This works perfectly fine for us but feel a bit hacky... is there another way to achieve the same results? Are we missing something?

Or is this something which can be useful for others? Maybe we can put this into a tiny package.

Please sign in or create an account to participate in this conversation.