Skip to content

Add doesntHavePermission and isNotAbleTo methods #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gdebrauwer
Copy link
Contributor

In my projects, I use the hasPermission a lot, but I almost always inverse the result as I want to check if a user doesn't have a permission:

class PostPolicy
{
    public function create(User $user)
    {
        if (! $user->hasPermission('some_permission')) {
            return false;
        }

       // more if-statements that check other conditions

       return true;
    }
}

This PR adds dedicated a doesntHavePermission method (and isNotAbleTo method), so those kind of checks are a bit more readable:

class PostPolicy
{
    public function create(User $user)
    {
        if ($user->doesntHavePermission('some_permission')) {
            return false;
        }

       // more if-statements that check other conditions

       return true;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant