- You want to limit access to the User Views Resource to only administrators.
- You only want the administrator to be able to create global favorite User Views.
- You want your users to be able to create their own User Views, but not make them globally or publicly available to other users.
- You want to disallow picking colors for User Views.
Policy Methods
makePublic() is used to control who can make a User View publicly available to the other users.
makeFavorite() is used to control who can add a User View to their favorites. Usually this will be enabled for all users.
makeGlobalFavorite() is used to control who can make a User View a global favorite for all users. Usually this would only be administrators.
selectIcon() is used to control if you want to allow your users to select an icon for a User View.
selectColor() is used to control if you want to allow your users to select colors for a User View.
Policy example
To make setting up these policies easy Advanced Tables includes a sampleUserViewPolicy. To implement this policy, first create your own policy:
UserViewPolicy and replace its contents with the contents in the example UserViewPolicy located in this plugin’s Policies directory.
Finally, even though Laravel may automatically detect your policy, it is recommended you explicitly register it in App\Providers\AuthServiceProvider:
Example policy assumptions
The example policy assumes:- You are using the default
User::classand that it’s located in theApp\Models\directory as has been the default since Laravel 8. - You have an
isAdmin()method on your user model.
Policies applied by example
The example policy will apply the following policies:- Only admins will be able to view the User Views Resource.
- All users can create User Views.
- Only admins or the owner of the User View can view, update, or delete their User View.
- Only admins can bulk delete User Views.
- All users can make their User Views public.
- All users can favorite their User Views or other user’s User Views.
- Only admins can make a User View a global favorite.
- All users can select an icon for their User Views.
- All users can select a color for their User Views.