public function scopeOrderByUniqueViews(Builder $query, string $direction = 'desc', $period = null): Builder
    {
        return $query->withCount(['views' => function ($query) use ($period) {
            $query->uniqueVisitor();

            if ($period) {
                $query->withinPeriod($period);
            }
        }])->orderBy('views_count', $direction);
    }
public function scopeOrderByUniqueViews(Builder $query, string $direction = 'desc', $period = null): Builder
    {
        return $query->withCount(['views' => function ($query) use ($period) {
            $query->uniqueVisitor();

            if ($period) {
                $query->withinPeriod($period);
            }
        }])->orderBy('views_count', $direction);
    }
public function scopeOrderByUniqueViews ( Builder $ query , string $ direction = 'desc' , $ period = null ) : Builder { return $ query -> withCount ( [ 'views' => function ( $ query ) use ( $ period ) { $ query -> uniqueVisitor ( ) ; if ( $ period ) { $ query -> withinPeriod ( $ period ) ; } } ] ) -> orderBy ( 'views_count' , $ direction ) ; }
Scope a query to order records by unique views count.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  string  $direction
@param  \CyrildeWit\EloquentViewable\Support\Period|null  $period
@return \Illuminate\Database\Eloquent\Builder
Scope a query to order records by unique views count .