More Edit:
one more thing, don't overthink where to have it in your directories.
Languages such as GOLANG doesn't even provide an initial structure. Just do it in a way that makes it clear what it does.
@ligonsker “Helpers” are just functions you haven’t thought about enough. If you have a large “helper”, then that’s almost certainly an indicator you need to re-factor and think about your code some more.
@martinbean In my case I don't think it's a helper (I wrote that it's a large function not helper), because I made some general code that would work with some unknown array length, so I used recursion. Right now in the Controller's method the way I need to use this code only take 15 lines of code. But, I added a few recursive functions at the bottom of the Controller which I don't think is the right place. that's why I want to move all this logic to a different place and only use it in a single line, that would return the data, something like:
$data = MyMethod::getData(); // or anything better
So it's more of a method I need to be able to reuse instead of declaring its recursive functions in every controller then invoke them with 15 lines
@Ligonsker What the method is will determine its name and the best place to put it for.
For example, controllers, models, queue jobs, etc are all just PHP classes with methods. But they get put in different directories depending on what those classes are doing. The same principle applies to the code you’re writing: if it’s a repository, put it in a “Repositories” directory; if it’s a service class, put it in a “Services” directory; etc.
@martinbean Alright, but even then, do I create a single class for every of these methods? Or maybe use a trait for all the functions?
In my case what the code eventually does is - I pass an array of empty arrays to it with some nested data and it re-arranges the data separately into these arrays in the way I want
Assuming I want to put it in Service folder. Should I also use it as a trait instead of just using use in the top of the controller?
Edit: so maybe have a "Traits" folder and inside of it I then create more folders like "service", "repositories". etc
Alright, but even then, do I create a single class for every of these methods? Or maybe use a trait for all the functions?
@Ligonsker It’s impossible to say without seeing the code. There’s no one rule of, “This is how your write code and this is where you store it”. Otherwise machines would be writing code and not humans 🙂
In my case what the code eventually does is - I pass an array of empty arrays to it with some nested data and it re-arranges the data separately into these arrays in the way I want
This sounds like a transformer. Have you looked at Eloquent API resources if you’re trying to present data in a specific format?
@martinbean it won’t be long with the progress made in the last few years in machine learning (OpenAi & such) until natural language will be enough to generate & combine enough code to produce full & complex applications.
Then it will just come back to imputing structure & design aspects & a lot of coding will become redundant, however I don’t believe it will ever replace the need for developers (and obviously people to maintain the knowledge of how to code the machines doing the coding)
@martinbean Yes but it's not exactly what I need in my case. Haha with ChatGPT I think it's coming soon, I'm definitely going to need to find a new job then😂😂😂😂
People seem to forget that things like ChatAI still need someone in the driver’s seat. Sure, they may be able to get to a point where they can generate code snippets based on user input, but they’re not coming up with business logic themselves, and code isn’t going to be 100% accurate.
Just like I wouldn’t trust an AI-only medical diagnosis; I’d rather someone who has studied and is able to give a diagnosis based on context and other factors; not just a particular symptom or set of symptoms I’ve typed into a program.