In my Database, I have:
tops
Tableposts
Tabletops_has_posts
Table.When I retrieve a
In Laravel 5.6+ (not sure about older versions) it's convenient to use this:
public function articles()
{
return $this->belongsToMany('Article', 'tops_has_posts')->withPivot('range')->orderBy('tops_has_posts.range');
}
In this case, whenever you will call articles
, they will be sorted automaticaly by range
property.