Answer the question
In order to leave comments, you need to log in
Where to write requests in Laravel? In the model, controller or repository?
The following questions have arisen related to using Eloquent ORM queries:
1. Where is the best place to work with Eloquent ORM queries in Laravel? In the documentation examples, nothing is specifically said, they write both in the methods of controllers and in the methods of models.
2. If queries are not written in the model, then how to use QUERY SCOPES, if it is real at all?
3. If you use repositories, then what should be written in the repository, and what should be written in the controller methods?
4. And in general, how to properly organize the structure of an application in Laravel? Where can I read about this for a beginner?
Thanks in advance for your replies.
Answer the question
In order to leave comments, you need to log in
If the request is of the form Post::with('author'), then it is possible in the controller, if the requests are complex, then take them to services .
There is no need to write queries in models, models for setting up links, scopes, etc.
Query scopes can be used anywhere. For example:Post::with('author')->customConditions()->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question