laravel:policies-and-authorization

Policies and Authorization

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "laravel:policies-and-authorization" with this command: npx skills add jpcaparas/superpowers-laravel/jpcaparas-superpowers-laravel-laravel-policies-and-authorization

Policies and Authorization

Use Policies for per-model actions; use Gates for cross-cutting checks.

Commands

Generate a policy

sail artisan make:policy PostPolicy --model=Post # or: php artisan make:policy PostPolicy --model=Post

Apply in routes (resource controllers)

Route::resource('posts', PostController::class); // In controller constructor $this->authorizeResource(Post::class, 'post');

One-off checks

$this->authorize('update', $post); // in controller Gate::allows('manage-billing', $user); // ad-hoc gate

Patterns

  • Use resource policy methods: viewAny, view, create, update, delete, restore, forceDelete

  • Prefer policy methods over inline checks; keeps controllers clean

  • Register policies in AuthServiceProvider

  • Use can middleware for quick route protection: ->middleware('can:update,post')

  • In tests, assert actingAs($user)->get(...)->assertForbidden() for denied cases

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

laravel:routes-best-practices

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:blade-components-and-layouts

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:queues-and-horizon

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:quality-checks

No summary provided by upstream source.

Repository SourceNeeds Review