Skip to content

[12.x] Fix Gate types #56582

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

Closed
wants to merge 1 commit into from
Closed

Conversation

mateusjatenee
Copy link
Contributor

@mateusjatenee mateusjatenee commented Aug 7, 2025

I believe the types added here are actually incomplete.
Gate::allows('view', $organization) and Gate::allows('create', Organization::class) are valid signatures, so we need to support passing class-strings and objects.

@mateusjatenee mateusjatenee changed the title [12.x] Fix Gate method types [12.x] Fix Gate types Aug 7, 2025
@devfrey
Copy link
Contributor

devfrey commented Aug 8, 2025

I think #56426 should just be reverted entirely. It doesn't make sense for the Gate to be generic. It's in no way bound to a specific object type.

@shaedrich
Copy link
Contributor

There's no way where going back to mixed is a good idea here. This prevents typing and static analysis. There has to be a better way.

@devfrey
Copy link
Contributor

devfrey commented Aug 8, 2025

There's no way where going back to mixed is a good idea here. This prevents typing and static analysis. There has to be a better way.

Why not? mixed is accurate. It doesn't even have to be an array, since Arr::wrap() is called. No part of the Gate implementation cares about the type of the first element of $arguments. There's also no way to narrow the type down on a specific Gate instance, because it doesn't hold a reference to the generic type.

Making Gate generic requires the template type to be known when a new instance is created. Gate::forUser() creates a new instance but doesn't specify the template type.

In summary: the generic type does not make sense here.

@27pchrisl
Copy link
Contributor

I've just hit this too. I believe you can have a custom Gate ability, custom argument interpreted by a custom handler, this sort of thing is technically allowed? So it really is mixed.

Gate::define('email', fn (User $user, string $email) => true);

Gate::authorize('email', 'hello@example.com').

@axlon
Copy link
Contributor

axlon commented Aug 8, 2025

I also just ran into this issue. I don't think Gate should be generic in the first place, but its kind of besides the point; changing interface arguments is a breaking change and shouldn't be done in a minor release. IMO the whole original change should be reverted

@shaedrich
Copy link
Contributor

Oh the jack of all trades device that doesn't let you type it …

@taylorotwell
Copy link
Member

Reverted that entire PR.

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.

6 participants