Skip to main content
Shopper uses spatie/laravel-permission to manage roles and permissions. Every admin user has one or more roles, and each role has a set of permissions that control access to admin panel sections and actions. Since all permissions are registered on Laravel’s gate, you can use Laravel’s built-in can() function and @can Blade directive. For a visual walkthrough of managing roles and permissions in the admin panel, see the User Guide pages: Managing Staff and Roles & Permissions.

Configuration

Roles are configured in config/shopper/admin.php. These names are used throughout the system for authorization checks:
Do not rename roles after they have been assigned to users. Role names are used in middleware and authorization checks throughout the system.

Models

Role

The model used is Shopper\Models\Role, which extends Spatie’s Role model with additional fields. The Role model provides an isAdmin() method:

Permission

The model used is Shopper\Models\Permission, which extends Spatie’s Permission model with grouping support.

Permission Groups

Permissions are organized into groups for display in the admin panel:
This returns the built-in groups: system, brands, categories, collections, products, customers, orders, discounts.

System Permissions

The system group contains the global capabilities that gate everything outside the resource permissions:
Since v2.8, access_setting is the only permission that grants write access to PaymentMethods, Currencies, Carriers, Team management, and Role/Permission management. Roles that previously relied on view_users to mutate these surfaces must be granted access_setting to keep working.

Generating Permissions

The Permission::generate() method creates five permissions for a given resource (browse, read, edit, add, delete):

Working with Roles

Creating Roles

To create a new role programmatically:

Assigning Roles

Assign a role to a user:

Checking Roles

The InteractsWithShopper trait on the User model provides role checking methods:

Working with Permissions

Checking Permissions

Use Laravel’s standard authorization:
In Blade templates:
In Livewire components, Shopper uses the authorize() method:

Creating Custom Permissions

To add a custom permission and assign it to a role:
Custom permissions without a recognized group appear in a “Custom permissions” section in the admin panel.

Revoking Permissions

To remove a permission from a role:

Admin User Creation

You can create an admin user from the command line:
Or programmatically:

Components

To customize the roles and permissions admin UI:
The relevant components in config/shopper/components/setting.php: