DEV Community

Discussion on: Question for PHP/Laravel developers.

Collapse
 
alchermd profile image
John Alcher • Edited

I follow this rule: Controllers are strictly for resource I/O, so a controller at max can only have seven public methods (one for each Restful actions). If it's not one of the following

ArticleController@index
ArticleController@create
ArticleController@store
ArticleController@show
ArticleController@edit
ArticleController@update
ArticleController@delete

... I move it to a separate controller. So let's say an article can be upvoted; instead of a custom ArticleController@upvote method, I create an UpvoteController@store instead. Take note that an upvote is not a concrete Eloquent model, but it can still be considered a resource.

TL;DR: A Controller doesn't necessarily have to map with an Eloquent model. Use it to group resource-related logic so you don't have to write custom controller methods.


Edit: I may have butchered that concept, I'm quite tired and can't type properly lol.

Collapse
 
mubarakky profile image
Mbo

Nice!. Please add a number so we can all keep track of the rules. LOL!