packy
107
5
Laravel

Best Practice Controller Methods

Posted 1 year ago by packy

Recently I watched the "Lets Build A Forum" series and made some choices to refactor a site from a year ago. Mostly I noticed my controllers were getting bloated with custom methods as opposed to a CRUD setup (index, create, store, edit, update, show, destroy). In the series it mentions to stay away from custom methods if you can, which i would agree with but sometimes I have some methods that don't fall in those categories.

For instance:

I have a LeagueController to which a league can do the standard CRUD methods but also I have some other situations that dont fall inline such as Approve and Join.

Join: when a posted to this route it will let a league owner know a user wants to join and adds that user to the league_user table waiting to be approved

Approve: If the league owner approves, a post hits this method and looks up the user on the league_user table and makes approved pivot column true

Now my question is what is best practice here? Just make custom methods? Make a new controller like ApprovalController then have Join be Store and Approve be Update? Just want to make sure my code is not a hot mess.

Any input would be great!

Thanks.

Please sign in or create an account to participate in this conversation.