Laravel add custom method to resource controller
10,204
Of course you can add new actions (methods) to RESTful controllers.
Just add method and create the route for this action:
Route::post('foo/bar', 'FooController@bar');
And don't forget to put this route before RESTful route:
Route::post('foo/bar', 'FooController@bar');
Route::resource('foo', 'FooController');
Author by
Eliya Cohen
Updated on June 05, 2022Comments
-
Eliya Cohen almost 2 years
I'm using laravel 5.2 and I wanted to know if there's an option to include into the resource more methods.
for example, Id'e like to create a POST method called
getUsersList
which I can limit the results. I know I can just add in the routes separately from the resource a new route, but I would need to do this for every route I do.What's the best way to do this?