Reputation: 693
In the laravel docs they have explained using resourceful controllers for using REST and using verbs in the methods of the controllers.
I have manually listed all my routes like this: Route::get('users/{id}/friends', 'UsersController@friends');
I am not using any resource just the method and the uri. How can I make this restful? Or is it restful already? Then how do I call the methods in a RESTful manner? I am confused
Upvotes: 0
Views: 215
Reputation: 2520
REST is nothing more than a convention on how data should transfer in the web. If you want to be all nitpicky about it check this out: http://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_constraints
As for laravel, when you generate a controller via the CLI like so:
php artisan controller:make UsersController
Laravel automatically creates the boiler plate for the various actions you need to be handling (create, store, destroy, update and so on.) and then you can set-up your routes. Of course you wont need all for most controllers.
Here's a helpful set of links from Phillip Brown's blog:
http://culttt.com/2013/07/01/setting-up-your-first-laravel-4-controller/
http://culttt.com/2013/08/12/building-out-restful-controller-methods-in-laravel-4/
Upvotes: 1
Reputation: 11
If you want to make it RESTful, the simplest way in laravel is to do Route::resource('user', 'UserController), which automatically gives you the routes shown on the laravel web page.
However, if you are trying to look up the friends RESTfully you would want to make a /friends/ resource, and then register it as Route::resource('friends', 'FriendController'). For more on the relationships/friends side of things I would suggest reading this question from 2011, while not laravel specific, it does answer questions about REST.
Upvotes: 0