In my Database, I have:
tops
Tableposts
Tabletops_has_posts
Table.
When I retrieve a top on my tops
table I also retrieve the posts
in relation with the top.
But what if I want to retrieve these posts in a certain order ?
So I add a range
field in my pivot table tops_has_posts
and I my trying to order by the result using Eloquent but it doesn't work.
I try this :
$top->articles()->whereHas('articles', function($q) {
$q->orderBy('range', 'ASC');
})->get()->toArray();
And this :
$top->articles()->orderBy('range', 'ASC')->get()->toArray();
Both were desperate attempts.
Thank you in advance.
See Question&Answers more detail:os