laravel:policies-and-authorization

Enforce Laravel access control with Policies, Gates, and can middleware.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2 --skill laravel-policies-and-authorization-patkik
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel:policies-and-authorization
Source: https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2/tree/main/.agents/skills/policies-and-authorization
Command: npx skills add https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2 --skill laravel-policies-and-authorization-patkik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enforce access control in Laravel applications using Policies and Gates to standardize controller protections.

Core Features & Use Cases

  • Enforce per-model access with Policies to guard controller actions
  • Use Gates for cross-cutting authorization checks
  • Apply can middleware for quick route protection
  • Register policies in AuthServiceProvider to centralize authorization rules

Quick Start

Define policies for your models and apply authorizeResource in your controllers to enforce standardized protections.

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 enforce per-model authorization in Laravel controllers?

You can enforce per-model authorization in Laravel by defining policies and applying the authorizeResource method within your controllers. This standardizes access control, automatically guarding specific controller actions against unauthorized users based on your policy logic.

What is the difference between using Gates and Policies for Laravel access control?

Laravel Gates and Policies both manage access control, but Policies are organized around specific models while Gates handle cross-cutting authorization checks. You can register policies in AuthServiceProvider to centralize rules and use Gates for broader, application-wide permissions.

How do I protect Laravel routes quickly using the can middleware?

You can protect Laravel routes quickly by attaching the can middleware to your route definitions. This applies authorization checks directly at the routing layer, verifying user permissions before the request reaches your controller logic, ensuring immediate route protection.

How do I register custom authorization rules in an AuthServiceProvider?

To register custom authorization rules in an AuthServiceProvider, define your policies and map them to their corresponding models within the boot method. This centralizes your access control logic, making it easy to manage and enforce across your application.

Does this approach work for testing authorization scenarios across typical Laravel projects?

Yes, this approach works for testing authorization scenarios across typical Laravel projects. By implementing policies and gates, you can simulate user permissions and assert that access control rules are properly enforced during your application test suites.

When should I use authorize() versus authorizeResource() for controller protection?

Use the authorize() method for manual, single-action controller protection, and use authorizeResource() to automatically apply authorization across all standard resource methods. Both rely on registered policies to enforce standardized access control throughout your controllers.