在使用 Routes 时,我注意到 Laravel 4 中的一些特殊之处。我有一个如下所示的路由组:
// Employers routes
Route::group(array('prefix' => 'employers'), function(
Route::get('/', array('as' => 'employers.index', 'uses' => 'EmployersController@index'));
Route::get('create', array('as' => 'employers.create', 'uses' => 'EmployersController@create'));
Route::post('/', array('as' => 'employers.store', 'uses' => 'EmployersController@store', 'before' => 'csrf'));
Route::get('search', array('as' => 'employers.search', 'uses' => 'EmployersController@search'));
Route::get('{id}', array('as' => 'employers.show', 'uses' => 'EmployersController@show'));
Route::get('{id}/edit', array('as' => 'employers.edit', 'uses' => 'EmployersController@edit'));
Route::patch('{id}/update', array('as' => 'employers.update', 'uses' => 'EmployersController@update', 'before' => 'csrf'));
Route::delete('{id}/destroy', array('as' => 'employers.destroy', 'uses' => 'EmployersController@destroy', 'before' => 'csrf'));
));
但是,我注意到,当我尝试添加新路由时,我必须在第一条路由之前添加它,以使用{id}
通配符作为其 url 中的第一个参数,否则我会得到一个notfoundhttpexception
. 这是正常的吗?因此,例如,这有效(在employers.search
路线中添加:
// Employers routes
Route::group(array('prefix' => 'employers'), function(
Route::get('/', array('as' => 'employers.index', 'uses' => 'EmployersController@index'));
Route::get('create', array('as' => 'employers.create', 'uses' => 'EmployersController@create'));
Route::post('/', array('as' => 'employers.store', 'uses' => 'EmployersController@store', 'before' => 'csrf'));
Route::get('{id}', array('as' => 'employers.show', 'uses' => 'EmployersController@show'));
Route::get('search', array('as' => 'employers.search', 'uses' => 'EmployersController@search'));
}
employers.search
结果找不到路由?