Back

I was watching a talk recently about testing your code (it might have been @nunomaduro 's talk on Pest 3?) that mentioned that your controllers should ONLY have the resource / CRUD methods in them.

I'm building a more complex app that has routes related to a user taking a test that's doing a lot more than just those methods. If not in a controller, where should those methods be placed?

I have a TestSessionController that handles all of the routes for the next question and grading the test and the questions. I am moving a lot of the functionality out of the controller and into Action classes, but I still use different methods in my controller to call those actions.

Or was that just an example of what could be done, and not necessarily a "best practice" sort of thing? Any help would be great!

3

246

It was an example but it's also a common patten. Adam Wathan gave a talk cruddy by design in 2017 where he says only have those methods in your class, once you need more create another class.

www.youtube.com/watch?v=MF0jFKvS4SI

1

175

@dcblogdev

Thank you so much for that video. I wish I had watched this a few months ago and maybe this project I’m wrapping up could have been made cleaner.

I don’t know if I would want to make EVERYTHING CRUD but it definitely gives me ideas in how to clean things up.

1

290

I always love these type of videos, can change how you build applications.

473