Open iget-master opened 5 years ago
You can just put the second route before user/{id}
and everything will work correctly, IIRC.
@iget-master
You can just put the second route before
user/{id}
and everything will work correctly, IIRC.
Yes, you could. But that's not the point. I just debugged this and it can be very confusing if, since it should be a no brainer to prefer more specific routes over unspecific.
I think this would be a great improvement for avoiding weird routing bugs
We in the past have used middleware to dynamically set the filter of for example {user} so only the ones allowed in the database were set.
But this only recommended if there aren't too many options for example a sites pages in which there wouldnt be thousands to set all the slugs.
Current behavior
If we have two routes that can match same URL, the router chooses the first defined route, eg:
If I access
http://localhost/user/current
it will result in a 404 error, because it goes to the first rule, try to resolve the route model binding, and fail as expected.Proposed behavior
Laravel should give some kind of specificity for each path slice, so if I access same url with same routes from previous sample, I get the
current
endpoint instead.I know that I can define a regex to the route parameter so it won't match on the first one. But, when using
Route::resource()
to generate routes, it defines the route without any regex, forcing me to manually write theshow
route for example.