2014-07-07 140 views
0

在我的前端我有collectionmodels。每个collection可以与后端通信,并且每个model也可以与后端通信。laravel路线组

我试图设计一种在这里正确的URL路径是什么,我想

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

你有什么问题? – ceejayoz

+0

这是做到这一点的正确方式,既RESTful和Laravel? – user391986

+0

您可以使用http://laravel.com/docs/controllers#resource-controllers。 – ceejayoz

回答

3

你在找什么是Laravel的RESTful资源路径。你可以阅读更多here

Route::group(array('prefix' => 'mycollection'), function() 
{ 
    Route::resource('/', '[email protected]'); 
}); 
+0

有没有办法让外面的第一个网址段,如果我不能这样做,那么我不能使用资源,将需要手动指定所有休息请求,并解析每个路线中的参数(post,put,get,删除)'''Route :: group(array('prefix'=>'mycollection'),function() {$ getFirstUrlSegment =''; Route :: resource('/',$ getFirstUrlSegment.'[email protected] '); });''' – user391986