ルートを使用する場合、Laravel 4 に少し特殊性があることに気付きました。次のような Route グループがあります。
// 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
が見つからないという結果になりますか?