-
Notifications
You must be signed in to change notification settings - Fork 11k
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 route regex registration methods #34997
Conversation
@@ -7,7 +7,7 @@ | |||
|
|||
class PendingResourceRegistration | |||
{ | |||
use Macroable; | |||
use Macroable, RouteRegexConstraintTrait; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This works
Route::apiResource('foo', 'FooController')->whereString('foo');
I find a whereString a bit confusing based on its name. For example, if I pass |
@taylorotwell Makes sense, I am renaming the method... |
Co-authored-by: Marek Szymczuk <marek@osiemsiedem.com>
Why not use the already existing validation rules syntax? Route::get('authors/{author}/{book}')->where('author', 'numeric'); Route::get('authors/{author}/{book}')->where('author', 'in:hi,bye'); it created a dependency between components but you find a good way to deal with it. |
@imanghafoori1 Laravel has a way to validate attributes of the http request in a cleaner way. This PR tries to shorten the definition of restrictions in the definition of routes and in their respective handlers. |
@gregorip02 Can you also add |
Let's see what @taylorotwell thinks, if this feature is useful I will be happy to add it. I think of an expression like the following. # Regex pattern
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} Route::get('users/{uuid}')->whereUuid('uuid'); |
These are amazing. Thank you, @gregorip02! It would be good to see that |
Great job but one question. I do not know about the others, but for me 99% of numerical restrictions in url is a pattern '[1-9][0-9]*' - allow numbers > 0. Do you also follow a similar pattern? |
This PR allows the developer to set restrictions on the route registration in a simple way. Also, drop unnecessary methods of #34361
Instead of having a statement similar to the following.
This same statement could be simplified with the following.
This also supports declaration of multiple parameters of the same grouped type.