0

I need to sort based on 2 fields a timeline of records that I have. In this result set I have these columns:

timeline:

- minutes (int);
- text;
- created_at (date_time);

In my timeline it is possible to have multiple text lines in the same minute. So having this in consideration, first I want to sort by minute, and then by created_at (in case I have multiple texts lines in the same minute).

My query doesn't work: I have for example minute 74 showing after 94 in DESC, and this is because in making the sort by both minute and created_at. I need to make sure that my sort is first in minutes, and then by created_at.

My code:

$timelineFeed = SoccerMatchTimeline::where('soccer_match_id',$id)
        ->orderBy('created_at', 'DESC')
        ->orderBy('minute', 'desc')->get();
Mr. Pyramid
  • 3,855
  • 5
  • 32
  • 56
Mcloud
  • 29
  • 1
  • 5

1 Answers1

4

I think you need to try this

$timelineFeed = SoccerMatchTimeline::where('soccer_match_id',$id)
        ->orderBy('minute', 'DESC')
        ->orderBy('created_at', 'desc')->get();

Since you have mentioned, that you need to sort first from minute then from created_at

Mr. Pyramid
  • 3,855
  • 5
  • 32
  • 56