Policy method is not getting generated as said in readme
hardiklakhalani opened this issue · 2 comments
This is what I did as per readme.md
Out of the box Shield handles the predefined permissions for Filament resources. So if that's all that you need you are all set. If you need to add a single permission (for instance lock) and have it available for all your resources just append it to the following config key:
permission_prefixes' => [
'resource' => [
'view',
'view_any',
'view_own', //<---- Want to have this additional Policy method by default generated for All. same as other permissions in this list
'create',
'update',
'restore',
'restore_any',
'replicate',
'reorder',
'delete',
'delete_any',
'force_delete',
'force_delete_any',
'lock', <--- So as per readme.md, I added this for testing this feature, but not working
],
...
],
But on running php artisan shield:generate --all
it's not adding lock()
method inside this file \app\Policies\FooPolicy.php
but it's adding view_own permissions in the Database for all the resource as expected though.
<?php
namespace App\Policies;
use App\Models\User;
use App\Models\Foo;
use Illuminate\Auth\Access\HandlesAuthorization;
class FooPolicy
{
use HandlesAuthorization;
...
...
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->can('view_any_foo');
}
/**
* Determine whether the user can reorder.
*/
public function reorder(User $user): bool
{
return $user->can('reorder_foo');
}
/**
* Determine whether the user can view own foo.
*/
public function viewOwn(User $user) //<-------- this is the requirement for all the resources
{
return $user->can('view_own_foo');
}
}
I added this question/bug (not sure) here because dedicated category seems 404
https://github.com/bezhanSalleh/filament-shield/discussions/new?category=q-a
I explored the vendor code, probably this function is executing the task
shield only generates the default policy methods and any permissions you define. but doesn't create custom policy methods.