Example #1
-1
 /**
  * Register periods macro.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  \Illuminate\Database\Eloquent\Model   $model
  * @return void
  */
 protected function registerMacro(Builder $query, Model $model)
 {
     /**
      * Query scope periods - filter this or last/next N periods
      *
      * @param  \Illuminate\Database\Eloquent\Builder $query
      * @param  string  $unit                                 Period type [minute|hour|day|week|month|year]
      * @param  integer $periods                              Number of past periods
      * @param  string  $column                               Column to match against
      * @param  integer $includeCurrent                       Whether to include current period in filter (additionally)
      * @return \Illuminate\Database\Eloquent\Builder
      *
      * @throws \InvalidArgumentException
      */
     $macro = function (Builder $query, $unit, $periods, $column = null, $includeCurrent = false) use($model) {
         if (!in_array($unit, ['minute', 'hour', 'day', 'week', 'month', 'year'])) {
             throw new InvalidArgumentException('Invalid period type');
         }
         // Developer may pass $includeCurrent instead of $column
         if (func_num_args() == 4 && is_bool($column)) {
             $includeCurrent = $column;
             $column = null;
         }
         $column = $column ?: $model->getPeriodColumnName();
         $range = $this->getPeriodRange($unit, $periods, $includeCurrent);
         return $query->whereBetween($column, $range);
     };
     $query->macro('periods', $macro);
 }