src/Node.php
public function scopeMostVisited(Builder $query, $limit = null)
    {
        $query->select(\DB::raw('nodes.*, count(*) as `aggregate`'))
            ->join('node_site_view', 'nodes.id', '=', 'node_site_view.node_id')
            ->groupBy('nodes.id')
            ->orderBy('aggregate', 'desc');

        if ($limit)
        {
            $query->limit($limit);
        }

        return $query;
    }
public function scopeMostVisited(Builder $query, $limit = null)
    {
        $query->select(\DB::raw('nodes.*, count(*) as `aggregate`'))
            ->join('node_site_view', 'nodes.id', '=', 'node_site_view.node_id')
            ->groupBy('nodes.id')
            ->orderBy('aggregate', 'desc');

        if ($limit)
        {
            $query->limit($limit);
        }

        return $query;
    }
public function scopeMostVisited ( Builder $ query , $ limit = null ) { $ query -> select ( \ DB :: raw ( 'nodes.*, count(*) as `aggregate`' ) ) -> join ( 'node_site_view' , 'nodes.id' , '=' , 'node_site_view.node_id' ) -> groupBy ( 'nodes.id' ) -> orderBy ( 'aggregate' , 'desc' ) ; if ( $ limit ) { $ query -> limit ( $ limit ) ; } return $ query ; }
Most visited scope

@param Builder $query
@param int|null $limit
@return Builder
Most visited scope