Kevin.a
Kevin.a

Reputation: 4296

Controllers in laravel

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?

Upvotes: 0

Views: 43

Answers (2)

Mahfuzul Alam
Mahfuzul Alam

Reputation: 3157

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

Upvotes: 1

Komal
Komal

Reputation: 2736

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..

Upvotes: 1

Related Questions