I have something like this
class Item extends Model
{
...
public function likes() {
return $this->hasMany('like');
}
...
In my controller I load this item like this
$items = Item::with([
...
'likes',
'comments',
...
])
->paginate(10);
I need to get likes count and order this list with paginate by this number something like this
$items = Item::with([
...
'likes',
'comments',
...
])
->orderBy(likes->count())
->paginate(10);
, which obviously is not working. Any tips ? Thanks.