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

Add support for additional where* methods to route groups #43731

Merged
merged 2 commits into from Aug 18, 2022
Merged

Add support for additional where* methods to route groups #43731

merged 2 commits into from Aug 18, 2022

Conversation

ollieread
Copy link
Contributor

@ollieread ollieread commented Aug 16, 2022

This PR addresses the change originally mentioned in #43509 and reverted in #43523.

Unlike the original PR, it adds support for all of the additional where* methods available on a route, to a route group, by adding the CreatesRegularExpressionRouteConstraints trait.

It works directly on the router, handled by Router::__call with an explicit check for beginning with where, that proxies to the method. There is no check to see if the method exists, because if it does not, it will be passed to the RouteRegistrar::attributes method automatically, so will achieve the same without the requirement for an additional condition.

Route::whereIn(['foo', 'bar'], ['one', 'two'])->prefix('/{foo}/{bar}')->group(function () {});

And on a RouteRegistrar, using the trait.

Route::prefix('/{foo}/{bar}')->whereIn(['foo', 'bar'], ['one', 'two'])->group(function () {});

This PR also adds 8 tests that test both of the approaches, as they are slightly different. No changes have been made to RouteRegistrar::allowedAttributes because the trait turns them into where attributes.

@ollieread ollieread changed the title Add supper for additional where* methods to route groups Add support for additional where* methods to route groups Aug 16, 2022
@morloderex
Copy link
Contributor

@ollieread Have you tested this with route caching enabled?

@ollieread
Copy link
Contributor Author

@ollieread Have you tested this with route caching enabled?

I have not, but I'm confident that I do not need to. Route groups already support where attributes, and these methods are wrappers for the where attribute. There is nothing new created because of this, it's just easier.

@taylorotwell taylorotwell merged commit 6c87065 into laravel:9.x Aug 18, 2022
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