Consider the following 3 lines of code in a routes file:

Route::pattern('token', '[0-9a-z]+');

Route::get('user/reset/{token}', 'UserController@getReset');

Route::controller('user', 'UserController');

Are the pattern and get routes serving any purpose in this example? As I understand it, the RESTful controller route at the bottom will match any user/reset/{target} URL to the UserController getReset action, regardless of any token pattern supplied.

Is it possible to use a regex constraint on a route like this, where there is also a "catch-all" controller route?

有帮助吗?

解决方案

The extra routes aren't needed in this example.

Right now, all the /user/reset requests are going to getReset. You could either send the constrained route to a different method, or neater, perform the validation in the controller to match the token and throw an exception if it doesn't match your constraints (or pass them off to your catch all idea).

Hope that helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top