Skip to main content
Depending on your application, you may not want to give all of your users the ability to use all the functions. Here are a few example situations:
  • 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.
Advanced Tables handles authorization with Laravel policies. Beyond Filament’s normal policy methods, Advanced Tables includes the following additional methods:

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 sample UserViewPolicy. To implement this policy, first create your own policy:
php artisan make:policy UserViewPolicy
Next, locate the newly created 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:
use App\Policies\UserViewPolicy;
use Archilex\AdvancedTables\Models\UserView;

protected $policies = [
    UserView::class => UserViewPolicy::class,
];

Example policy assumptions

The example policy assumes:
  1. You are using the default User::class and that it’s located in the App\Models\ directory as has been the default since Laravel 8.
  2. You have an isAdmin() method on your user model.

Policies applied by example

The example policy will apply the following policies:
  1. Only admins will be able to view the User Views Resource.
  2. All users can create User Views.
  3. Only admins or the owner of the User View can view, update, or delete their User View.
  4. Only admins can bulk delete User Views.
  5. All users can make their User Views public.
  6. All users can favorite their User Views or other user’s User Views.
  7. Only admins can make a User View a global favorite.
  8. All users can select an icon for their User Views.
  9. All users can select a color for their User Views.