Answer the question
In order to leave comments, you need to log in
How to make a selection with grouping in Laravel?
Good afternoon!
There is a task, and rather trivial. There are two entities: order and complaints. One-to-many relationship. At the same time, orders must be pulled out of the database for display in the feed. Suppose we have 10 complaints for one order, 1 for another, and 3 for a third. The order of complaints - first there were complaints to the second, then to the first, then to the third. Three orders will be displayed (instead of 14 - by the number of complaints), and in the order 3-1-2.
I hope I didn't explain too confusingly.
I tried group by - I catch an error due to sql strict mode. Perhaps you need to write this case with a subquery?
Help me please)
Answer the question
In order to leave comments, you need to log in
The explanation is really confusing but I think I get it.
Apparently you need to extract the orders, sorting them by the number of complaints for each of them. (Correct me if I misunderstood the task)
If so, then you do not need grouping, Laravel has a built-in functionality for counting related records: https://laravel.com/docs/5.7/eloquent-relationship...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question