laravel:policies-and-authorization

SkillDev tools

Enforce access via Policies and Gates; use authorize() and authorizeResource() to standardize controller protections

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the laravel:policies-and-authorization skill

What this skill tells your AI

The instructions your AI receives, as published by jpcaparas/superpowers-laravel in skills/policies-and-authorization/SKILL.md and read by ahel’s review.

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

Laravel 13+: Authorization Attributes

use Illuminate\Routing\Attributes\Controllers\Authorize;
use Illuminate\Routing\Attributes\Controllers\Middleware;

#[Middleware('auth')]
class CommentController
{
    #[Authorize('create', [Comment::class, 'post'])]
    public function store(Post $post) { /* ... */ }

    #[Authorize('delete', 'comment')]
    public function destroy(Comment $comment) { /* ... */ }
}
  • Attributes keep the policy check visible at the action; equivalent to $this->authorize(...) — pick one style per codebase (see laravel:php-attributes)

Signals

GitHub stars
153
Forks
2
Last commit
Jul 2026
Advanced
Catalog kind
skill
Gateway key
laravel-policies-and-authorization
Source
github.com/jpcaparas/superpowers-laravel