I have a model that I want to sort based on a relationship property.
The main model, Resultado
, has a relation respondente
, of type belongsTo
, and respondente
has a relation usuario
.
I want to get Resultado
with those relations and sort the results by usuario
name
property (column).
I tried
$resultados = Diagnostico\Resultado::with('respondente.usuario')
->orderBy('usuarios.name')->get();
but that trows a "Column not found 'usuarios.name'" mysql error.
How can I sort the Resultado
model based on its relationships?
EDIT:
The table for Resultado
model is diag_resultados
. As I wrote in the comments, I had to use join to achieve the right result.