문제

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