在我的前端,我有一个collection
models
。每个collection
都可以与后端进行通信,每个model
也可以与后端进行通信。
我正在尝试为它设计正确的网址路线,这就是我的想法
create [POST] /mycollection
update [PATCH] /mycollection/22
delete [DELETE] /mycollection/22
和模型
create [POST] /mycollection/22
update [PATCH] /mycollection/22/3
delete [DELETE] /mycollection/22/3
我应该如何在Laravel中创建路线?
我正在调查路线组,但它看起来还是相当多的锅炉板。
Route::group(array('prefix' => 'mycollection'), function()
{
Route::get('{id}', function($id){});
Route::post('/', function(){});
Route::patch('{id}', function($id){});
Route::destroy('{id}', function($id){});
Route::get('{id}/{child_id}', function($id, $child_id){});
Route::post('{id}', function($id){});
Route::patch('{id}/{child_id}', function($id, $child_id){});
Route::destroy('{id}/{child_id}', function($id, $child_id){});
});
答案 0 :(得分:3)
您正在寻找的是使用Laravel的RESTful资源路由。您可以阅读更多here
Route::group(array('prefix' => 'mycollection'), function()
{
Route::resource('/', 'CollectionController@index');
});