Laravel

Laravel Authorization Policies

January 16, 2026 1 min read 16 views

Authorization with policies:

Create Policy

php artisan make:policy PostPolicy --model=Post

Policy Methods

class PostPolicy
{
    public function update(User $user, Post $post): bool
    {
        return $user->id === $post->user_id;
    }

    public function delete(User $user, Post $post): bool
    {
        return $user->id === $post->user_id || $user->isAdmin();
    }
}

Use in Controller

$this->authorize('update', $post);

Use in Blade

@can('update', $post)
    
@endcan
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!