Agent skill
policies
Centralised authorization logic for a given Eloquent model. Policies define per-ability access control and are enforced at the controller level.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/policies
SKILL.md
Name: Policies Description: Centralised authorization logic for a given Eloquent model. Policies define per-ability access control and are enforced at the controller level. Compatible Agents: general-purpose, backend Tags: app/Policies/**/*.php, laravel, php, backend, policy, authorization, auth
Rules
- Policy classes live in
app/Policies/ - Naming:
PascalCasewith aPolicysuffix, named after the model they protect:InvoicePolicy,PostPolicy - Policies centralise all authorization logic for a given model in one place
- Create one policy for each model
- Define one method per ability — use standard names:
viewAny,view,create,update,delete,restore,forceDelete - Always enforce authorization at the controller level — never inside actions or services
- Laravel auto-discovers policies that follow the
ModelPolicynaming convention - For custom locations, register manually in
AuthServiceProvider
Examples
namespace App\Policies;
use App\Models\Invoice;
use App\Models\User;
class InvoicePolicy
{
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Invoice $invoice): bool
{
return $user->id === $invoice->user_id || $user->isAdmin();
}
public function create(User $user): bool
{
return $user->hasVerifiedEmail();
}
public function update(User $user, Invoice $invoice): bool
{
return $user->id === $invoice->user_id && $invoice->isDraft();
}
public function delete(User $user, Invoice $invoice): bool
{
return $user->isAdmin();
}
}
// Usage in controller
public function update(UpdateInvoiceRequest $request, Invoice $invoice): InvoiceResource
{
$this->authorize('update', $invoice);
// ...
}
// Usage in Form Request
public function authorize(): bool
{
return $this->user()->can('update', $this->route('invoice'));
}
// Usage via route middleware
Route::put('/invoices/{invoice}', [InvoiceController::class, 'update'])
->middleware('can:update,invoice');
Anti-Patterns
- Putting authorization logic directly in controllers, actions, or models
- Creating global gates instead of model-specific policies when model-based auth is appropriate
- Not creating a policy for each model
- Putting business logic inside a policy method (belongs in Actions or Services)
- Using
return trueinauthorize()without documenting the intent
References
- Laravel Authorization
- Related:
Controllers/SKILL.md— the layer where policies are enforced - Related:
FormRequests/SKILL.md— can usecan()inauthorize()method
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?