0Pricing
PHP Academy · Lesson

Policies: Model-Based Authorization

Attach policies to Eloquent models and use them in controllers.

What is a Policy?

A Policy is a class that organises authorization logic for a specific Eloquent model. Policies are recommended when you have multiple authorization actions for the same model.

Generating a Policy

Use Artisan to generate a policy. Add --model to pre-fill standard methods.

$ php artisan make:policy PostPolicy --model=Post

All lessons in this course

  1. Authentication with Laravel Breeze
  2. Protecting Routes with Middleware
  3. Gates: Simple Authorization Checks
  4. Policies: Model-Based Authorization
← Back to PHP Academy