laravel-permission-development

Implement roles, permissions, middleware, and Blade directives with Spatie Laravel Permission.

Updated Aug 14, 2026
One-click install
npx skills add https://github.com/bill80362/laravel-thread-admin --skill laravel-permission-development-bill80362
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-permission-development
Source: https://github.com/bill80362/laravel-thread-admin/tree/main/.junie/skills/laravel-permission-development
Command: npx skills add https://github.com/bill80362/laravel-thread-admin --skill laravel-permission-development-bill80362

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires spatie/laravel-permission.

What problem does it solve? Managing authorization in Laravel applications becomes error-prone when roles and permissions are scattered across controllers, routes, and views. This Skill provides structured guidance for implementing role-based access control with the spatie/laravel-permission package, covering setup through production patterns. ## Core Features & Use Cases - Role and Permission Management: Create, assign, sync, and revoke roles and permissions using package methods, enums, and idempotent seeders. - Access Control Enforcement: Apply middleware aliases on routes, check authorization with $user->can(), and render conditional UI with Blade directives like @can and @role. - Advanced Patterns: Configure Super Admin via Gate::before, write permission-aware policies, enable teams for multi-tenancy, and manage the permission cache. - Use Case: When building a multi-user admin panel, use this Skill to seed roles like 'admin' and 'writer', protect routes with role: middleware, and hide edit buttons from unauthorized users in Blade templates. ## Quick Start Ask the AI to set up Spatie Laravel Permission with an admin role, an edit-articles permission, route middleware protection, and a seeder that flushes the permission cache.

Frequently Asked Questions about laravel-permission-development

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Spatie Laravel Permission in a Laravel project?

Add the HasRoles trait to your User model, which includes HasPermissions. Then create roles and permissions with Role::create() or the idempotent findOrCreate() methods, and assign roles to users with assignRole().

How do I protect Laravel routes with roles and permissions middleware?

Register the role, permission, and role_or_permission middleware aliases in bootstrap/app.php, then apply them to routes like middleware(['role:manager|writer']). The pipe character provides OR logic, and a guard can be specified after a comma.

Should I check permissions or roles in Laravel authorization?

Check permissions using $user->can() rather than roles, since apps should verify permissions while roles merely group them. This approach also supports Super Admin overrides via Gate::before, which role checks bypass.

How do I create a Super Admin with Spatie Laravel Permission?

Define a Gate::before callback in AppServiceProvider::boot() that returns true when the user has the Super Admin role. It must return null rather than false for other users so normal permission checks still run.

Why are new permissions not working after seeding in Laravel?

The package caches permissions, so stale cache causes new permissions to be unrecognized. Call app()[PermissionRegistrar::class]->forgetCachedPermissions() at the start of your seeder or after direct database inserts.

Does Spatie Laravel Permission support multi-tenancy with teams?

Yes, enable the teams option in config/permission.php before running migrations, then set the active team with setPermissionsTeamId() in middleware. When switching teams, unset the cached roles and permissions relations on the user.