0

如何使用路由在 url 中传递多个可选参数?

http://example.com/user
http://example.com/user/22
http://example.com/user/25/disable

Route::resource('users', 'AdminController@users', array('before'=>'auth'));

Route::get('users/{id}', 'AdminController@users', array('before'=>'auth'));
Route::post('users/{id}', 'AdminController@users', array('before'=>'auth'));

Route::get('users/{id}/{pages}', 'AdminController@users', array('before'=>'auth'));
Route::post('users/{id}/{pages}', 'AdminController@users', array('before'=>'auth'));
4

1 回答 1

0

反转路线:

Route::get('users/{id}/{pages}', 'AdminController@users', array('before'=>'auth'));
Route::post('users/{id}/{pages}', 'AdminController@users', array('before'=>'auth'));

Route::get('users/{id}', 'AdminController@users', array('before'=>'auth'));
Route::post('users/{id}', 'AdminController@users', array('before'=>'auth'));

Route::resource('users', 'AdminController@users', array('before'=>'auth'));

因为否则“ http://example.com/user/25/disable ”将首先命中 Route::resource() ,并首先与 /user 匹配

于 2013-08-17T08:53:35.617 回答