How to install and setup spatie roles and permission in Laravel 11
Install and Setup Laravel 11 Spatie roles and permissions tutorial step by step
In this post, you will be learning how to install and setup the Spatie Permission Package in Laravel 11.x version. Follow the below steps to get started:
Step 1: Install the Laravel Application
Install Laravel with the following command:
Setup the Database in .env file
Install the Authentication package as per your requirement. So I will use Laravel Breeze
After successfully installing the Laravel Breeze package, run the below artisan command to install in the application.
once breeze:install is completed, run the below command to migrate the:
Step 2: Install the Spatie Package with the following command
2.1: install the package via composer
After installing the spatie larvel permission package.
2.2: Lets App the Service Providers as follows:
Go to the folder 'bootstrap/providers.php' file and paste the below code:
2.3: Let's publish the migration and the config/permission.php config file with
2.4: Run the migration command:
Step 3: Setup the Middleware
This package comes with RoleMiddleware, PermissionMiddleware and RoleOrPermissionMiddleware middleware. You can add them inside your bootstrap/app.php file to be able to use them through aliases.
Go to the folder 'bootstrap/app.php' file and paste the below code:
Step 4: Add the necessary trait to your User model ( app/Models/User.php ) :
That's all dev. We have seen how to install and Setup the Spatie Roles & Permission package in Laravel 11
I hope this helped you.