0

I would like to know when it's the best to create a controller.

I mean why can't we just use 1 controller for all our functions.

For example I have this controller called forumcontroller

why can't I just put all my functions in that controller and then do something like.

forumcontroller@function1

forumcontroller@function2

forumcontroller@function3

When is it best to create a new one?

4
  • 3
    The point is to keep things simple and readable. But if you have 20 different forum-related methods, and you ask 20 different programmers, you're going to get wildly differing opinions on where and how you should stick all of them. This question is inevitably opinion-based. That's not to say it's a bad question - it's really a good one. Just not suitable for SO. Commented Oct 4, 2016 at 11:52
  • 1
    It is not about Laravel is about MVC good topic also on SO stackoverflow.com/questions/5735761/… Commented Oct 4, 2016 at 11:53
  • @JoelHinz Very clear! Commented Oct 4, 2016 at 12:16
  • @Froxz Thanks for the extra information, I'll take a look at that. Commented Oct 4, 2016 at 12:17

2 Answers 2

1

It's a good practice to crate different controllers for different module like UserController for user module, ForumController for forum module, BookingController for booking module etc.. It's easy to handle your code..

Sign up to request clarification or add additional context in comments.

Comments

1

It's all about readability, simplicity, refactoring and design patterns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.