Gates: Simple Authorization Checks
Define and evaluate gates for user-action permission logic.
What Are Gates?
Laravel Gates are closures that determine if a user is authorised to perform a given action. They are simple, global authorization checks not tied to a specific model.
Defining a Gate
Define gates in App\Providers\AppServiceProvider or a dedicated AuthServiceProvider using the Gate facade.
<?php
use Illuminate\Support\Facades\Gate;
// In a service provider's boot() method:
Gate::define("delete-post", function (User $user, Post $post) {
return $user->id === $post->user_id;
});All lessons in this course
- Authentication with Laravel Breeze
- Protecting Routes with Middleware
- Gates: Simple Authorization Checks
- Policies: Model-Based Authorization