lc-generate-spatie-permissions
Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | lc:generate-spatie-permissions |
| description | Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder. |
| argument-hint | [ModelName] |
| user-invocable | true |
| allowed-tools | Read Grep Bash Edit Write Glob |
Scaffold the roles & permissions setup for spatie/laravel-permission: add the HasRoles trait to the target model (default User) and generate a roles & permissions seeder following the project's conventions.
This is a generator skill — it always creates files, no analyze or fix mode. It is specific to spatie/laravel-permission; other permission packages (e.g. larallow) get their own generator.
| Subcommand | Description |
|---|---|
| (no argument) | Default to the User model. Ask which roles/permissions to scaffold. |
[ModelName] | Add HasRoles to the given model and generate the seeder. |
Grep to check whether spatie/laravel-permission is in composer.json.spatie/laravel-permission is not installed. Install it with:
composer require spatie/laravel-permission
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
config/permission.php exists and the permissions/roles tables are referenced). If config/permission.php is missing, tell the user to run the vendor:publish + migrate commands above before proceeding.Read from vendor so the generated code matches the installed version, not assumptions:
Read vendor/spatie/laravel-permission/src/Traits/HasRoles.php to confirm the trait namespace (Spatie\Permission\Traits\HasRoles).Read config/permission.php for the configured models (Permission, Role classes), guard_name defaults, and column_names.Spatie\Permission\Models\Role, Spatie\Permission\Models\Permission, unless the project overrides them in config).User by default. Resolve its path (app/Models/{Model}.php).web. Ask if the project uses a non-default guard (e.g. api).admin, user; permissions per resource as view-X, create-X, update-X, delete-X) and confirm before writing — do NOT invent a large matrix unprompted.Read app/Models/{Model}.php.use Spatie\Permission\Traits\HasRoles; at the top.use HasRoles; inside the class (alongside existing traits).Create database/seeders/RolesAndPermissionsSeeder.php (skip/append if it already exists — never overwrite without confirmation):
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;
class RolesAndPermissionsSeeder extends Seeder
{
public function run(): void
{
app(PermissionRegistrar::class)->forgetCachedPermissions();
$permissions = [
// 'view-posts', 'create-posts', 'update-posts', 'delete-posts',
];
foreach ($permissions as $permission) {
Permission::findOrCreate($permission, 'web');
}
$admin = Role::findOrCreate('admin', 'web');
$admin->givePermissionTo(Permission::all());
Role::findOrCreate('user', 'web');
}
}
Requirements:
forgetCachedPermissions() first — new permissions won't apply otherwise.findOrCreate (idempotent) so the seeder is safe to re-run.web if the project differs).$permissions and roles with what the user actually asked for. Keep it minimal — no extra logging, comments, or unrequested roles.Glob/Read).Read database/seeders/DatabaseSeeder.php.$this->call(RolesAndPermissionsSeeder::class); to its run() if not already present.php -l on the changed files (Docker-aware: detect container from docker-compose.yml).php artisan db:seed --class=RolesAndPermissionsSeeder.// Assign
$user->assignRole('admin');
$user->givePermissionTo('update-posts');
// Check
$user->hasRole('admin');
$user->can('update-posts');
// Blade
@can('update-posts') ... @endcan
@role('admin') ... @endrole
// Route middleware (see note below — the alias must be registered in v6)
Route::put('/posts/{post}', ...)->middleware('permission:update-posts');
If the user wants to use the permission:/role: route middleware, remind them that spatie v6 does not auto-register the aliases. Offer to add them:
bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
]);
})
app/Http/Kernel.php $middlewareAliases:
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
Gate::before unless the user asks.HasRoles or the seeder already exists, report it and ask before modifying./lc:spatie-permissions-audit to verify everything lines up.Create a Larascraper scraper (v2 or v3) for a target website, chaining browser actions (click, type, wait, scroll), conditional flow (when/repeatUntil), captcha solving, and file/PDF downloads. Detects the installed major and generates the matching style.
Add or edit a Laracrate file collection in config/laracrate.php with the correct anatomy (disk, access, types, variants, previews, extract/embed, flags, per-model scoping).
Runtime-verified Laravel inspection using the Laravel Boost MCP server (Tinker, Database Query/Schema, Last Error) instead of static grep. Falls back to Docker/Tinker if Boost is not installed.
Audit spatie/laravel-permission usage - permissions used in code but undefined, defined but unused, unprotected routes, guard mismatches, and cache pitfalls.
Extract business logic from a controller or Livewire component method into a Laractions Action class.
Create a Laractions action class with proper boilerplate.