About laravel-policies-and-authorization
A Laravel authorization skill for developers, covering Policies for model actions and Gates for cross-cutting checks, with route protection and testing guidance.
Key features
- 01Use Policies for model actions
- 02Apply Gates to cross-cutting checks
- 03Protect routes with can middleware
- 04Test denied authorization
Use cases
- 01Generate and configure model Policies
- 02Protect resource controller routes
- 03Check responses to unauthorized access
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ noartem/ skills --skill laravel-policies-and-authorizationAfter installing, type/laravel-policies-and-authorizationin Claude Code to confirm it loaded.
Details
From the project READMEPolicies 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
canmiddleware for quick route protection:->middleware('can:update,post') - In tests, assert
actingAs($user)->get(...)->assertForbidden()for denied cases
Comments
Markdown supported