Answer the question
In order to leave comments, you need to log in
How to extract logic from models?
Now at me the main logic of work with a DB is taken out in services. They pull models and do something. But in fact, all methods in services are static. don't store anything at all. In fact, just a set of functions responsible for a particular model. Well, if you think about it, then there is no difference between the model itself, in general. Of course, you can store an instance of the model in the service, but there is no difference between Auth::user() and $this->getUser(); even worse. What would be the best way to do it? There is no business logic, in fact, only CRUD with models. Leave everything in the models and pull their methods directly from the controller? The project is simple, no abstractions, entities, please do not suggest :) it is full of useless repositories.
Is there a way to scatter the code in the model into different classes, grouping them according to a common meaning, but so that they are all one model? More specifically, behavior. Or use services like me is it ok?
Answer the question
In order to leave comments, you need to log in
Is there a way to scatter the code in the model into different classes, grouping them according to a common meaning, but so that they are all one model?
but it doesn't matter whether Auth::user() or $this->getUser();
fed up with useless repositories
First of all, repositories are not useless.
Secondly, everything that has been invented or is being invented makes sense, but not everywhere and not always.
If you have a simple CRUD application why do you need services?
Most likely you wanted to offload the controllers and actually moved the code from one place to another.
And what kind of code can be shared if it's just CRUD.
Eloquent already has all the magic to create crud
User::create()
User::update()
User::find()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question