๐ Auth / Gates / Policies
Authentication state, Gate checks, Policy authorization
Auth State
| Auth::check() | false |
| Auth::guest() | true |
| Auth::id() | null |
| Auth::user()->name | null |
// Gates โ AppServiceProvider::boot()
Gate::define('demo-gate', fn($u) => true);
// Check
Gate::check('demo-gate'); // bool
Gate::authorize('demo-gate'); // throws
$user->can('demo-gate');
// Policy โ PostPolicy
public function update(User $u, Post $p): bool
{ return $u->id === $p->user_id; }
// Controller
$this->authorize('update', $post);
// Blade
@can('update', $post) ... @endcan
Blade Auth Directives
โ Inside @guest block
โ @can('update', $post) โ denied (login as post owner)