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 inconfig/shopper/admin.php. These names are used throughout the system for authorization checks:
Models
Role
The model used isShopper\Models\Role, which extends Spatie’s Role model with additional fields.
The Role model provides an
isAdmin() method:
Permission
The model used isShopper\Models\Permission, which extends Spatie’s Permission model with grouping support.
Permission Groups
Permissions are organized into groups for display in the admin panel:system, brands, categories, collections, products, customers, orders, discounts.
System Permissions
Thesystem 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
ThePermission::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
TheInteractsWithShopper trait on the User model provides role checking methods:
Working with Permissions
Checking Permissions
Use Laravel’s standard authorization:authorize() method:
Creating Custom Permissions
To add a custom permission and assign it to a role:Revoking Permissions
To remove a permission from a role:Admin User Creation
You can create an admin user from the command line:Components
To customize the roles and permissions admin UI:config/shopper/components/setting.php: