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

[8.x] Add gate policy callback #39185

Merged
merged 7 commits into from
Oct 14, 2021
Merged

[8.x] Add gate policy callback #39185

merged 7 commits into from
Oct 14, 2021

Conversation

cbl
Copy link
Contributor

@cbl cbl commented Oct 13, 2021

This pr adds the ability to pass policy callbacks to the gate.

Usage

Gate::inspect([PostPolicy::class, 'update'], $post)->authorize();
Gate::inspect(InvokablePolicy::class)->authorize();
Gate::check([PostPolicy:class, 'update'], $post);
Gate::any([PostPolicy::class, ['update', 'edit']], $post);

Why This Is Usefull

  • This allows navigating to the namespace of the policy from where it is used.
  • Different policies can be used for the same model.

@taylorotwell
Copy link
Member

Can you look at the AuthorizesRequests trait? It does some argument parsing before calling into the gate and it may need to be updated to support these changes.

I will mark this PR as draft until that is done - please mark it as active when you are ready for me to review it again.

@taylorotwell taylorotwell marked this pull request as draft October 13, 2021 13:59
@cbl
Copy link
Contributor Author

cbl commented Oct 13, 2021

@taylorotwell I changed the trait so the it works when an array is passed to the authorize method. However calling the __invoke method when only passing a class name would introduce a breaking change as a different method name is guessed by the trait.

@cbl cbl marked this pull request as ready for review October 13, 2021 14:47
@taylorotwell taylorotwell merged commit 02c5dc5 into laravel:8.x Oct 14, 2021
driesvints added a commit that referenced this pull request Oct 21, 2021
@driesvints
Copy link
Member

Reverting this. See #39267

taylorotwell pushed a commit that referenced this pull request Oct 21, 2021
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.

None yet

3 participants