spatie avatar

Laravel Permission Development

This handles everything around Spatie's laravel-permission package: setting up roles and permissions, middleware guards, Blade directives, policies, and even teams for multi-tenancy. The source is thorough on best practices, like always checking permissions (not roles) with `$user->can()`, avoiding direct user permissions, and using `Gate::before` for super admin patterns. It covers the stuff you forget between projects, like flushing the permission cache when seeding or which middleware to use for OR logic in routes. If you're building any Laravel app with user authorization beyond basic gates, this consolidates the practical patterns in one place instead of rereading docs every time.

skills.sh installs
310
GitHub stars
13K
last updated
Aug 21, 2026

Install

$ npx -y skills add spatie/laravel-permission --skill laravel-permission-development --agent claude-code

Installs into .claude/skills of the current project.

Files

Laravel Permission Development

When to use this skill

Use this skill when working with authorization, roles, permissions, access control, middleware guards, or Blade permission directives using spatie/laravel-permission.

Core Concepts

  • Users have Roles, Roles have Permissions, Apps check Permissions (not Roles).
  • Direct permissions on users are an anti-pattern; assign permissions to roles instead.
  • Use $user->can('permission-name') for all authorization checks (supports Super Admin via Gate).
  • The HasRoles trait (which includes HasPermissions) is added to User models.

Setup

Add the HasRoles trait to your User model:

use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

Creating Roles and Permissions

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit articles']);

// findOrCreate is idempotent (safe for seeders)
$role = Role::findOrCreate('writer', 'web');
$permission = Permission::findOrCreate('edit articles', 'web');

Assigning Roles and Permissions

Sponsors

Details

Repository
github.com/spatie/laravel-permission
Categories
Backend & APIs, DevOps & CI/CD, PHP & Laravel
First seen
Jun 3, 2026
1davila7 avatarclaude-opus-4-5-migrationdavila7/claude-code-templatesMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5. Use when the user wants to update their codebase, prompts, or API calls to308skills.sh installs
2rysweet avatardocumentation-writingrysweet/amplihackWriting clear, discoverable software documentation following the Eight Rules and Diataxis framework. Use when creating README files, API docs, tutorials, how-to308skills.sh installs
3secondsky avatarnuxt-studiosecondsky/claude-skillsThis skill should be used when the user asks to "set up Nuxt Studio", "configure Studio OAuth", "deploy Studio to Cloudflare", "add visual editor to Nuxt", "con308skills.sh installs
4patricio0312rev avatarreadme-generatorpatricio0312rev/skillsGenerates comprehensive README files with badges, installation, usage, API docs, and contribution guidelines. Use when users request "README", "project document307skills.sh installs
5senpi-ai avatarautonomous-tradingsenpi-ai/senpi-skillsGive your agent a budget, a target, and a deadline — it does the rest. Orchestrates DSL + Opportunity Scanner + Emerging Movers into a full autonomous trading l307skills.sh installs
6aicoincom avataraicoin-onchainaicoincom/coinos-skillsUse this skill for **on-chain DEX trading and wallet operations on EVM/Solana chains**: token swap quotes, swap execution, wallet portfolio/balance queries, gas306skills.sh installs