我正在尝试为Series设置Route:resource
。
当我创建个人的get,post,patch和delete Routes时,它可以按预期运行(例如GET series/${serie}
)。
但是,当我使用Route :: resource时,它会创建多个属性(例如GET series/${series}
)。
在我关注的laracast中,它会创建单数(例如GET projects/${project}
)。
我找不到我想要的东西。
这有效:
Route::get('/series', 'SeriesController@index');
Route::get('/series/create', 'SeriesController@create');
Route::get('/series/{serie}', 'SeriesController@show');
Route::post('/series', 'SeriesController@store');
Route::get('/series/{serie}/edit', 'SeriesController@edit');
Route::patch('/series/{serie}', 'SeriesController@update');
Route::delete('/series/{serie}', 'SeriesController@destroy');
路线列表为:
GET|HEAD | series | App\Http\Controllers\SeriesController@index
POST | series | App\Http\Controllers\SeriesController@store
GET|HEAD | series/create | App\Http\Controllers\SeriesController@create
GET|HEAD | series/{serie} | App\Http\Controllers\SeriesController@show
PATCH | series/{serie} | App\Http\Controllers\SeriesController@update
DELETE | series/{serie} | App\Http\Controllers\SeriesController@destroy
GET|HEAD | series/{serie}/edit | App\Http\Controllers\SeriesController@edit
这不起作用:
Route::resource('series', 'SeriesController');
并生成此路由列表:
GET|HEAD | series | App\Http\Controllers\SeriesController@index
POST | series | App\Http\Controllers\SeriesController@store
GET|HEAD | series/create | App\Http\Controllers\SeriesController@create
GET|HEAD | series/{series} | App\Http\Controllers\SeriesController@show
PATCH | series/{series} | App\Http\Controllers\SeriesController@update
DELETE | series/{series} | App\Http\Controllers\SeriesController@destroy
GET|HEAD | series/{series}/edit | App\Http\Controllers\SeriesController@edit
注意复数形式{series}。为什么会这样?
答案 0 :(得分:0)
“系列”是单词的复数形式和单数形式,因此Laravel生成的路线完全正确。
如果您查看Laravels复数助手,甚至可以看到“系列”被明确列为不可数:https://github.com/laravel/framework/blob/5.5/src/Illuminate/Support/Pluralizer.php#L49