Skip to content
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

[4.x] Add tokenCant() helper function to HasApiTokens #552

Merged

Conversation

chester-sykes
Copy link
Contributor

@chester-sykes chester-sykes commented Dec 11, 2024

This PR adds tokenCant() helper function to the HasApiTokens trait. It allows you to check if the accessToken does not have an ability. It is the opposite of the current tokenCan helper function.

    public function tokenCant(string $ability)
    {
        return ! $this->tokenCan($ability);
    }

It will be helpful to people who want to do something if a token does not have the ability, for example:

abort_if($user->tokenCant('foo'), 403)

I think its a bit more readable than:

abort_if(! $user->tokenCan('foo'), 403)

It won't break any existing features as this PR does not change any existing code.

@taylorotwell taylorotwell merged commit 6980642 into laravel:4.x Dec 11, 2024
5 checks passed
@chester-sykes chester-sykes deleted the 4.x_token_cant_helper_function branch December 13, 2024 01:36
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.

2 participants