Laravel & Ecosystem (50 Qs)•Part 2: Eloquent ORM, Security & Queue Ecosystem (11 - 24)
How does Laravel handle Authentication and Authorization (Gates vs Policies)?
mid LevelSecurity & AuthData Structures
In Simple Words:
- Authentication: Verifies who the user is (handled via Laravel Breeze, Jetstream, or Fortify).
- Authorization: Verifies what the user is allowed to do:
- Gates: Closure-based authorization for simple, ad-hoc actions:
Gate::define('edit-settings', fn(User $user) => $user->isAdmin); - Policies: Dedicated classes organized around specific Eloquent models:
$this->authorize('update', $post);callsPostPolicy::update(User $user, Post $post).
- Gates: Closure-based authorization for simple, ad-hoc actions: