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

245

In response to @FinalAsgard

First thing if your project is old and running from long it's okay to not update those methods.

So remember one sentence before anything else 'if you need other methods than these golden 7 methods means you need another controller.

Now let's see one example.

You have PostController and you already have 7 methods in it. And now you need 2 methods which make post draft and published. So you can create PublishedPostController and put store/update for publishing the post and destroy for making it draft.

🦹🦹

198

  • No matching results...
  • Searching...

/ 1000