🔴 Laravel Intermediate

What are Policies in Laravel?

Answer

Policies are classes that organize authorization logic around a particular model or resource. Generate: php artisan make:policy PostPolicy --model=Post. Define authorization methods: public function update(User $user, Post $post): bool { return $user->id === $post->user_id; }. Register in AuthServiceProvider or use auto-discovery. Check in controllers: $this->authorize("update", $post) — throws 403 if unauthorized. In Blade: @can("update", $post) ... @endcan. Via Gate: Gate::allows("update", $post). Policies support viewAny, view, create, update, delete, restore, forceDelete methods. The before() method can grant blanket permissions to admins before any other check.