laravel-policies-and-authorization

Centralizes Laravel access control with Policies and Gates.

Updated Jun 8, 2025
One-click install
npx skills add https://github.com/noartem/kawa --skill laravel-policies-and-authorization-noartem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-policies-and-authorization
Source: https://github.com/noartem/kawa/tree/main/ui/.ai/skills/laravel-policies-and-authorization
Command: npx skills add https://github.com/noartem/kawa --skill laravel-policies-and-authorization-noartem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enforces consistent access control across Laravel applications by centralizing authorization logic into Policies and Gates, reducing scattered auth checks.

Core Features & Use Cases

  • Per-model action checks via policies (viewAny, view, create, update, delete, etc.)
  • Cross-cutting checks via gates
  • Register policies in AuthServiceProvider
  • Use can middleware for quick route protection
  • Patterns for testing authorization

Quick Start

Create a policy for a Post model and apply authorizeResource in your PostController to protect routes.

Frequently Asked Questions about laravel-policies-and-authorization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I centralize Laravel authorization logic using policies and gates?

To centralize Laravel authorization, you define per-model access rules in policies and cross-cutting checks in gates. You register these in the AuthServiceProvider to ensure consistent protections across typical web apps without scattering auth checks.

What is the best way to protect Laravel controller routes with policies?

Protect Laravel controller routes by applying the authorizeResource() method within your controller for standard CRUD actions, or use the can middleware directly on your routes for quick, centralized access control enforcement.

How do I test Laravel policies and authorization gates?

Testing Laravel policies involves verifying that specific user roles can or cannot perform per-model actions. You apply established testing patterns against your registered gates and policies to validate consistent access control before deployment.

When should I use Laravel gates instead of policies for access control?

Use Laravel gates for cross-cutting authorization checks that span multiple models or actions, and use policies for per-model action checks like view, create, update, or delete. Both are registered in the AuthServiceProvider for consistent enforcement.

Does the can middleware work for route protection in Laravel applications?

Yes, the can middleware works for quick route protection in Laravel. You apply it directly to your routes to enforce centralized authorization rules defined in your registered policies and gates before requests reach the controller.