php - Sorting by a related table -


if this,

booking::query()->with('vehicle') 

laravel generates 2 queries:

select * `bookings`  select * `vehicles` `vehicles`.`id` in (?, ?, ?, ?, ?, ?, ?, ?) 

can tell laravel left join instead can orderby on vehicles.name? each booking has 1 vehicle, wouldn't generate records.

i'm aware can db::table('booking')->leftjoin instead, doesn't populate models.

there 2 things can do. first change query to:

booking::leftjoin('vehicle', 'vehicle.booking_id', '=', 'booking.id')->get(); // or whatever fields 

the other sort collection after results. there example in documentation. check here : http://laravel.com/docs/eloquent#collections hope helps


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -