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

Gate::after method not update results #50097

Closed
MertcanDinler opened this issue Feb 15, 2024 · 6 comments
Closed

Gate::after method not update results #50097

MertcanDinler opened this issue Feb 15, 2024 · 6 comments

Comments

@MertcanDinler
Copy link

Laravel Version

10.44.0

PHP Version

8.3

Database Driver & Version

No response

Description

"Similar to the before method, if the after closure returns a non-null result that result will be considered the result of the authorization check."

This is how the Gate::after method is described in the Laravel documentation. However, it does not function as described. Instead, it returns the result prior to calling the 'callAfterCallbacks' method if the parameter '$result' is non-null.

Steps To Reproduce

\Illuminate\Support\Facades\Gate::define('some-permission', function ($user) {
    return false; //for example check any permission for user
});

\Illuminate\Support\Facades\Gate::after(function ($user, $ability, $result) {
    return true; //for example is admin
});

\Illuminate\Support\Facades\Gate::inspect('some-permission', App\Models\User::first())->allowed() //returns false;
@MertcanDinler MertcanDinler changed the title Gate::after method update results Gate::after method not update results Feb 15, 2024
@driesvints
Copy link
Member

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@MertcanDinler
Copy link
Author

Hi @driesvints, thanks for the fast response!

I followed your instructions reproduced the issue in this repository: https://github.com/MertcanDinler/laravel-gate-bug.
This is the exact commit: MertcanDinler/laravel-gate-bug@73dba65

and i fix at #50098 pull request

@driesvints
Copy link
Member

After reviewing this, it seems the current behaviour is the expected one.

@MertcanDinler
Copy link
Author

@driesvints I think the function does not perform the function described in the document. Can you explain the purpose of the function?

@driesvints
Copy link
Member

@MertcanDinler it's a catch all for when no conditions were hit.

@MertcanDinler
Copy link
Author

I think the documentation needs to be updated to be more descriptive of this method.
Thanks.

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

No branches or pull requests

2 participants