How to sort by a field of the pivot table of a many-to-many relationship in Eloquent ORM
Not sure if you plan to move to Laravel 4, but here’s an Eloquent example for sorting by a pivot tables fields: public function songs() { return $this ->belongsToMany(‘Song’) ->withPivot(‘play_count’) ->orderBy(‘pivot_play_count’, ‘desc’); } withPivot is like the eloquent with and will add the play_count field from the pivot table to the other keys it already … Read more