Vote count:
0
I have tables as,
foos(a,b,c)
bars(e,f,g)
In the controllers I am using, $foos = Foo::with('Bar');
Now to sort the values with b as ascending I can write,
$foos = Foo::with('Bar')->orderBy('b', 'asc')->get();
However, sorting is not working for the fields that are part of eagerly loaded models, for example this code is not sorting anything. What might be the reason?
$foos = Foo::with(array('Bar' => function($query){
$query->orderBy('g', 'desc');
}))->get();
asked 23 secs ago
Laravel orderBy() function does not work for eagerly loaded model
Aucun commentaire:
Enregistrer un commentaire