Learn how to manage roles and permissions in your Laravel application
user
and admin
Run seeder command to add these roles to the database:
/admin/roles
route in your browser and click on the “New Role” button.
/admin/permissions
route in your browser and click on the “New Permission” button.
/admin/users
route in your browser
role
and permission
middleware provided by the Spatie Laravel Permission package.
HasRoles
trait also adds role and withoutRole scopes to your models to scope the query to certain roles or permissions:
withoutRole
scopes can accept a string, a \Spatie\Permission\Models\Role
object or an \Illuminate\Support\Collection
object.
The same trait also adds scopes to only get users that have or don’t have a certain permission.
\Spatie\Permission\Models\Permission
object or an \Illuminate\Support\Collection
object.