Hi pickles. I would suggest you separate functionalities into different controllers. Because i believe that this functions can be categorised according to what they do. Otherwise get ready for a maintainance nightmare.
Thanks for the reply.. Normally with PHP, I'd use an include to pull in different files with functions to break it up. Is there a similar way to do with controllers, to act as include files or components to support the main controller?
Because it goes through a cycle of tasks.. so every http request needs to go through all these tasks one at a time.
task 1 task 2 task 3 task 4..
So I'd love to be able to break these task into separate files, so they're easy to manage. Thanks!
A controller shouldn't be responsible for much more than accepting a request and telling the application what to do next. Look at building out a service responsible for performing the operation, splitting the code across multiple files will only hinder you further. If you're writing a 3000 line method it's an indication that you have serious architectural problems with your code, might be worth spending some time learning about OOP! There are lots of really great resources available (books, videos).
Actually I should say my method is not 3000 lines.. the whole file is about 3000 lines total. There are quite a number of methods in it, but even that, I am finding hard to manage.. just keeping track of all the methods inside it, I was thinking might be easier if I could break it up somehow.
as citricsquid said controllers shouldnt do all that stuff, maybe look at repositories pattern. It is bad to put this kind of logic into controller because then it is tied to specific request (url). If you know for sure (10000%) that it will stay that way for ever, it is ok, but if you move it to seperate class, you will be able to use it in different controllers as well.
Normally with PHP, I'd use an include to pull in different files with functions to break it up.
Laravel still is just PHP, so you could do that. You could look into traits.
Or create base task class with common functionality and each task (1, 2, 3...) extends base task and adds task specific functionality, so your 3000 file would be split in to four parts.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community