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

[9.x] Add "whereIn" route parameter constraint method #41794

Merged
merged 2 commits into from
Apr 2, 2022
Merged

[9.x] Add "whereIn" route parameter constraint method #41794

merged 2 commits into from
Apr 2, 2022

Conversation

Propaganistas
Copy link
Contributor

@Propaganistas Propaganistas commented Apr 2, 2022

Alternative for #41776, as suggested by @taylorotwell

An enum is often used as a model attribute to simplify DX while still efficiently persisting integers in the database. There are ample of situations where a model's enum would be included in a route as well. Currently Laravel is only able to implicitly resolve string-backed enum route bindings, but that sort of contradicts the aforementioned use case.

By adding a whereIn constraint method, one can easily restrict a parameter to only a few valid values. It's not even limited to enums. Any array will fit.

Route::get('/foo/{bar}')->whereIn('bar', $values);

@taylorotwell taylorotwell merged commit 0cc725b into laravel:9.x Apr 2, 2022
@Propaganistas Propaganistas deleted the route-wherein branch April 2, 2022 18:13
@GrahamCampbell GrahamCampbell changed the title Add "whereIn" route parameter constraint method [9.x] Add "whereIn" route parameter constraint method Apr 2, 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.

2 participants