agentsclimarketplace

Laravel policies and authorization

Skill ComeOnOliver/skillshub/skills/noartem/skills/laravel-policies-and-authorization

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill laravel-policies-and-authorization

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

0.9 KB, as published. Nobody here has run it

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

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.