user391986
user391986

Reputation: 30956

route groups in laravel

In my front end I have a collection of models. Each collection can communicate with the back end and each model can also communicate with the back end.

I am trying to devise the proper url routes for it here is what I am thinking

create [POST] /mycollection
update [PATCH] /mycollection/22
delete [DELETE] /mycollection/22

and for the models

create [POST] /mycollection/22
update [PATCH] /mycollection/22/3
delete [DELETE] /mycollection/22/3

How should I create my routes in Laravel?

I'm looking into route groups but it's still quite a bit of boiler plate it seems.

  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){});
  });

Upvotes: 0

Views: 107

Answers (1)

Mitch
Mitch

Reputation: 1394

What you are looking for is RESTful resource routes with Laravel. You can read more here

Route::group(array('prefix' => 'mycollection'), function()
{
    Route::resource('/', 'CollectionController@index');
});

Upvotes: 3

Related Questions