jeudi 4 février 2016

Laravel: Using minimal nested routes with controllers

I'm using Laravel 5.2 to create a REST API, and I'm trying to follow the best practices for API design, documented here. One of the points mentions minimising path nesting, like so:

In data models with nested parent/child resource relationships, paths may become deeply nested, e.g.:

/orgs/{org_id}/apps/{app_id}/dynos/{dyno_id}

Limit nesting depth by preferring to locate resources at the root path. Use nesting to indicate scoped collections. For example, for the case above where a dyno belongs to an app belongs to an org:

/orgs/{org_id}
/orgs/{org_id}/apps
/apps/{app_id}
/apps/{app_id}/dynos
/dynos/{dyno_id}

From http://ift.tt/1X54EJr

What is the best way to do this using Laravel's controllers and routes? Currently I am using:

Route::resource('orgs', 'OrganisationController', ['except' => ['edit', 'create']]);
Route::resource('apps', 'AppController', ['except' => ['edit', 'create']]);

Currently, I'm thinking I need to add another single route for orgs/{org_id}/apps/, which uses only the AppController@index method. These are only examples, I have a lot of resources so the above code would have to be repeated for each one.

Is this the best way of doing things, or is there a cleaner alternative that i'm not aware of?

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1nOKuHN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire