Reputation: 9464
When I add additional methods to a resource controller, like for example getHistory()
or getStats()
, the only way I can auto-detect them to avoid writing more routes is like that:
Route::controller('users','UsersController');
Route::resource('users','UsersController');
I believe the controller method will route only the prefixed methods and the resource method will not override them.
Is there not a better way to define custom routes according to additional methods inside a resource controller? Like an array as a parameter to it?
Upvotes: 2
Views: 1573
Reputation: 3750
You correct in that controller methods have to be prefixed with http verb. Adding custom methods to controllers is as easy as this:
public function getCustom() {}
public function postCustom() {}
Resourceful controllers on the other hand are a little different. Adding additional method to those and having them auto-detected is more complex.
Defining the Route::controller()
first followed by the Route::resource
is the best way to have the best of both worlds; a resourceful api with custom routes.
I read a post the other day, about how you can add custom methods to resources. I'll try and find it then link you to it.
EDIT: Here is a link to another SO question similar that you may find helpful - https://stackoverflow.com/a/16661564/1233455
Upvotes: 2