php - Laravel Eloquent - Ordering by specific ID of the child -


i have 3 models: schedule, shift, , user. schedule has many shift, , each shift belongs schedule , has 1 user.

to schedule (with shifts , user), use:

schedule::with(['shifts', 'shifts.user'])->find($id); 

i want order schedule specific user id - i.e. if looking @ schedule, want shift first 1 on schedule.

all find online how order parent eloquent model (i.e. schedule here) using orderbyraw()

user::orderbyraw(db::raw("field(id, $user_id)")); 

i tried put in $query of with statement, didn't work:

schedule::with(     [         'shifts',          'shifts.user' => function($query) use ($user_id)         {             $query->orderbyraw(db::raw("field(id, $user_id)"));         }     ])->find($id); 

any ideas?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -