Been stuck for a while now even after reading docs & examples. I am trying to get a collection ordered by price. The price attribute is nested in a relation that needs to be accessed by the user ID and the service type ID. Here is the relation between tables in which there is the criteria I need to use for sorting:
EDIT Here is something working thanks to @jarek :-)
$users_available = $users_available->join('stypes_4_user', function($join)use($stype)
{
$join->on('user_id', '=', 'users.id')
->where('service_type_id', '=', $stype);
})
->orderBy('price', 'desc')->get();
EDIT 2
If you ever end up struggling after using a ->select('*')
after the join and not being able to access your model's methods make sure you are calling 'yourtablename.*'
and not just '*'
. read more here:
http://jpcamara.com/selecting-carefully-laravel-joins/