public function scopeWithinPeriod(Builder $query, Period $period)
    {
        $startDateTime = $period->getStartDateTime();
        $endDateTime = $period->getEndDateTime();

        if ($startDateTime && ! $endDateTime) {
            $query->where('viewed_at', '>=', $startDateTime);
        } elseif (! $startDateTime && $endDateTime) {
            $query->where('viewed_at', '<=', $endDateTime);
        } elseif ($startDateTime && $endDateTime) {
            $query->whereBetween('viewed_at', [$startDateTime, $endDateTime]);
        }

        return $query;
    }
public function scopeWithinPeriod(Builder $query, Period $period)
    {
        $startDateTime = $period->getStartDateTime();
        $endDateTime = $period->getEndDateTime();

        if ($startDateTime && ! $endDateTime) {
            $query->where('viewed_at', '>=', $startDateTime);
        } elseif (! $startDateTime && $endDateTime) {
            $query->where('viewed_at', '<=', $endDateTime);
        } elseif ($startDateTime && $endDateTime) {
            $query->whereBetween('viewed_at', [$startDateTime, $endDateTime]);
        }

        return $query;
    }
public function scopeWithinPeriod ( Builder $ query , Period $ period ) { $ startDateTime = $ period -> getStartDateTime ( ) ; $ endDateTime = $ period -> getEndDateTime ( ) ; if ( $ startDateTime && ! $ endDateTime ) { $ query -> where ( 'viewed_at' , '>=' , $ startDateTime ) ; } elseif ( ! $ startDateTime && $ endDateTime ) { $ query -> where ( 'viewed_at' , '<=' , $ endDateTime ) ; } elseif ( $ startDateTime && $ endDateTime ) { $ query -> whereBetween ( 'viewed_at' , [ $ startDateTime , $ endDateTime ] ) ; } return $ query ; }
Scope a query to only include views within the period.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  \CyrildeWit\EloquentViewable\Support\Period  $period
@return \Illuminate\Database\Eloquent\Builder
Scope a query to only include views within the period .