order - Laravel multiple orderBy on same column -


first i'm including things tried, think it's quite self explanatory i'm trying do.

$event->load(['dates' => function($q) {   $q->where( db::raw('date(start_time)'), '>=', carbon::now()->format('y-m-d'))    ->orderby('start_time', 'asc')     ->where( db::raw('date(start_time)'), '<', carbon::now()->format('y-m-d'))    ->orderby('start_time', 'desc');  }]); 

or

$event->load(['dates' => function($q) {   $q->where( db::raw('date(start_time)'), '>=', carbon::now()->format('y-m-d'))    ->orderby('start_time', 'asc')     ->orwhere(function($query) {       $query->where( db::raw('date(start_time)'), '<', carbon::now()->format('y-m-d'))            ->orderby('start_time', 'desc');      });  }]); 

what i'm trying do

i have events table hasmany relation dates. i'm trying eager load related dates first in ascending order upcoming dates , in descending order dates have passed.

with try, orderby ordering all results , not where query. how approach problem?


many - correct answer of course voted , selected answer.

you can't have 2 different orders on same query. can have however, 2 subqueries, each own order, unioned want them be.


Comments