J
J
jazzus2019-06-30 18:11:17
Laravel
jazzus, 2019-06-30 18:11:17

How to apply second orderBy in query?

The code

Model::orderBy('field','desc')
     ->take(100)
     ->orderBy('field','asc')
     ->take(50)
     ->get();

Uses only the first orderBy. Second sorting only from the collection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2019-06-30
@jazzus

Well, I can still understand double sorting. But what are you trying to achieve with the second limit, what result do you expect? Are you really trying to sort the same field first in descending order and then in ascending order? What result do you expect in this case?
In general, multiple sorting is indicated in this way - under the hood, Eloquent collects all sorts into an array and applies them one by one. The problem you have is that the request is somehow meaningless.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question