Skip to content
Back to skills

Policies And Authorization

ASecurity

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

  • 147 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added June 6, 2026
toolsphp

Security analysis

A100/100

Scanned June 6, 2026

npx -y skills add jpcaparas/superpowers-laravel --skill policies-and-authorization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Policies And Authorization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Policies And Authorization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jpcaparas-policies-and-authorization/badge)](https://www.skillsdirectory.com/skills/jpcaparas-policies-and-authorization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel:policies-and-authorization
description: Enforce access via Policies and Gates; use authorize() and authorizeResource() to standardize controller protections
---

# 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.