Learn how to implement a robust Laravel roles and permissions system using the Spatie Laravel Permission package. This step-by-step tutorial covers everything from installation to middleware configuration, ensuring your application has a professional ACL (Access Control List) setup.
✅ In this video, you'll learn:
→ Installing Spatie Permission via Composer.
→ Publishing & running migrations for roles and permissions tables.
→ Implementing the HasRoles trait in the User model.
→ Configuring Middleware to protect your routes.
🛠️ Step-by-Step Implementation Guide
1. Install the package: composer require spatie/laravel-permission
2. Publish migration and config: php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
3. Run migrations: php artisan migrate
4. Add the HasRoles trait to your User model:
PHP
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable {
use HasRoles;
}
5. Configure Middleware (App\Http\Kernel or Bootstrap/App): Add the aliases for role and permission to handle route protection.
#Laravel11 #Spatie #LaravelPermissions #WebDev #PHPTutorial #ACL #LaravelCoding #BackendDevelopment
📲Stay Connected
→ / @tech4knowhow
→https://github.com/tech4knowhow
→ / tech4knowhow
→ https://t.me/tech4knowhow
→ / misgana-tesfaye