I have read some answers over here but I'm not able to adapt it to my problem. I would like to order a collection where I use whereHas. I have two tables profissao_user and users. It is returning the users but I would like to orderBy the table profissao_user by desc order on raio_deslocacao.
$users = User::whereHas('profissoes', function ($query){
$query->where('profissao_id', 1)
->orderBy('profissao_user.raio_deslocacao', 'desc');
})->where('concelho_id', 2)->get();
I would like to order it by raio_deslocacao. As you can guess the result returned is not sorted by desc order. I have tested switing desc to asc but it doens't change the order. If I do something alone these lines
$users = User::whereHas('profissoes', function ($query){
$query->where('profissao_id', 1);
})->where('concelho_id', 2)->orderBy('stars', 'desc')->get();
It works wonders (ordering the outer statment). What am I missing here?