当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::whereBetween方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::whereBetween方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereBetween方法的具体用法?PHP Builder::whereBetween怎么用?PHP Builder::whereBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Builder的用法示例。


在下文中一共展示了Builder::whereBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: whereBetween

 /**
  * between, 两端开区间
  * @param $attribute
  * @param null $min
  * @param null $max
  * @return static
  */
 public function whereBetween($attribute, $min, $max)
 {
     if ($min > $max) {
         return $this->whereEquals(0, 1);
     }
     $this->original->whereBetween($attribute, [$min, $max]);
     return $this;
 }
开发者ID:zhwei,项目名称:laravel-lego,代码行数:15,代码来源:EloquentTable.php

示例2: applyFilters

 private function applyFilters(Builder $query, $expression, $value, $multiple = false)
 {
     $equalsFilter = false;
     $field = null;
     $filter = explode(":", $expression);
     // filter[field:filter]=value
     if (count($filter) == 2) {
         $field = $filter[0];
         $filter = $filter[1];
     } else {
         $equalsFilter = true;
         $field = $expression;
     }
     // filter[field]=value
     if ($equalsFilter) {
         $multiple ? $query->orWhere($field, '=', $value) : $query->where($field, '=', $value);
     }
     // filter[field:between]=A,B
     if ($this->isBetweenFilter($filter)) {
         $betweenValues = $this->getBetweenValues($value);
         if (count($betweenValues) != 2) {
             throw new BadRequestHttpException("Please specify two numbers to filter between");
         }
         $multiple ? $query->orWhereBetween($field, $betweenValues) : $query->whereBetween($field, $betweenValues);
     }
     // filter[field:[after, before, greater_than, less_than]]=value
     if ($this->isComparisonFilter($filter)) {
         if ($this->isDateFilter($field)) {
             $value = Carbon::createFromTimestamp($value);
         }
         $comparisonFilter = $this->getComparisonFilter($filter);
         $multiple ? $query->orWhere($field, $comparisonFilter, $value) : $query->where($field, $comparisonFilter, $value);
     }
     // filter[field:[contains, ends_with, starts_with]]=value
     if ($this->isWildcardFilter($filter)) {
         $value = $this->getLikeWildcard($filter, $value);
         $multiple ? $query->orWere($field, 'like', $value) : $query->where($field, 'like', $value);
     }
     // filter[field:trashed]=true
     if ($this->isTrashedFilter($field)) {
         $query->onlyTrashed();
     }
 }
开发者ID:hrobinson,项目名称:laravel-core,代码行数:43,代码来源:FilterableRepository.php

示例3: filterDates

 /**
  * Filter dates in query.
  *
  * @param  string $startDate
  * @param  string $endDate
  * @return $this
  */
 protected function filterDates($startDate = null, $endDate = null)
 {
     if (is_null($startDate) && !is_null($endDate)) {
         $this->query->where($this->gridQuery->dateReferenceColumn(), '<=', $endDate);
     }
     if (!is_null($startDate) && !is_null($endDate)) {
         $this->query->whereBetween($this->gridQuery->dateReferenceColumn(), [$startDate, $endDate]);
     }
     return $this;
 }
开发者ID:sedp-mis,项目名称:base-report,代码行数:17,代码来源:ReportQueryBuilder.php

示例4: applyFilter

 public function applyFilter(Filter $filter, $operator, array $params)
 {
     $column = $filter->getField();
     $sqlLikeEscapes = ['%' => '\\%', '_' => '\\_'];
     switch ($operator) {
         // Zero-parameter operators
         case 'empty':
             $this->query->where(function ($query) use($column) {
                 $query->whereIn($column, ['', 0])->orWhereNull($column);
             });
             break;
         case 'not-empty':
             $this->query->where(function ($query) use($column) {
                 $query->whereNotIn($column, ['', 0])->whereNotNull($column);
             });
             break;
             // Single-parameter operators
         // Single-parameter operators
         case 'eq':
             $this->query->where($column, $params[0]);
             break;
         case 'ne':
             $this->query->where(function ($query) use($column, $params) {
                 $query->where($column, '!=', $params[0])->orWhereNull($column);
             });
             break;
         case 'lt':
             $this->query->where($column, '<', $params[0]);
             break;
         case 'gt':
             $this->query->where($column, '>', $params[0]);
             break;
         case 'lte':
             $this->query->where($column, '<=', $params[0]);
             break;
         case 'gte':
             $this->query->where($column, '>=', $params[0]);
             break;
         case 'starts-with':
             $this->query->where($column, 'LIKE', strtr($params[0], $sqlLikeEscapes) . '%');
             break;
         case 'ends-with':
             $this->query->where($column, 'LIKE', '%' . strtr($params[0], $sqlLikeEscapes));
             break;
         case 'contains':
             $this->query->where($column, 'LIKE', '%' . strtr($params[0], $sqlLikeEscapes) . '%');
             break;
         case 'not-starts-with':
             $this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
                 $query->where($column, 'NOT LIKE', strtr($params[0], $sqlLikeEscapes) . '%')->orWhereNull($column);
             });
             break;
         case 'not-ends-with':
             $this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
                 $query->where($column, 'NOT LIKE', '%' . strtr($params[0], $sqlLikeEscapes))->orWhereNull($column);
             });
             break;
         case 'not-contains':
             $this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
                 $query->where($column, 'NOT LIKE', '%' . strtr($params[0], $sqlLikeEscapes) . '%')->orWhereNull($column);
             });
             break;
             // Dual-parameter operators
         // Dual-parameter operators
         case 'between':
             $this->query->whereBetween($column, $params);
             break;
         case 'not-between':
             $this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
                 $query->whereNotBetween($column, $params)->orWhereNull($column);
             });
             break;
             // Unlimited-parameter operators
         // Unlimited-parameter operators
         case 'in':
             $this->query->whereIn($column, $params);
             break;
         case 'not-in':
             $this->query->whereNotIn($column, $params);
             break;
     }
     return $this;
 }
开发者ID:nhusby,项目名称:mason-laravel,代码行数:83,代码来源:EloquentContainer.php

示例5: apply

 /**
  * @param Builder $where
  * @param array   $filters
  * @param string  $boolean
  */
 protected static function apply(Builder $where, array $filters, $boolean)
 {
     foreach ($filters as $filterName => $valuePair) {
         foreach ($valuePair as $key => $value) {
             if (is_array($value) && count($value) > 0) {
                 $value = array_values($value);
                 if (count($value[0]) > 1) {
                     switch ($filterName) {
                         case BaseFilter::RANGES:
                             $where->whereBetween($key, [$value[0][0], $value[0][1]], $boolean);
                             break;
                         case BaseFilter::NOT_RANGES:
                             $where->whereNotBetween($key, [$value[0][0], $value[0][1]], $boolean);
                             break;
                     }
                 } else {
                     switch ($filterName) {
                         case BaseFilter::GROUP:
                             $where->whereIn($key, $value, $boolean);
                             break;
                         case BaseFilter::NOT_GROUP:
                             $where->whereNotIn($key, $value, $boolean);
                             break;
                     }
                 }
             }
             $value = (array) $value;
             $value = array_shift($value);
             switch ($filterName) {
                 case BaseFilter::GREATER_THAN_OR_EQUAL:
                     $where->where($key, '>=', $value, $boolean);
                     break;
                 case BaseFilter::GREATER_THAN:
                     $where->where($key, '>', $value, $boolean);
                     break;
                 case BaseFilter::LESS_THAN_OR_EQUAL:
                     $where->where($key, '<=', $value, $boolean);
                     break;
                 case BaseFilter::LESS_THAN:
                     $where->where($key, '<', $value, $boolean);
                     break;
                 case BaseFilter::CONTAINS:
                     $where->where($key, 'LIKE', '%' . $value . '%', $boolean);
                     break;
                 case BaseFilter::NOT_CONTAINS:
                     $where->where($key, 'NOT LIKE', '%' . $value . '%', $boolean);
                     break;
                 case BaseFilter::STARTS_WITH:
                     $where->where($key, 'LIKE', $value . '%', $boolean);
                     break;
                 case BaseFilter::ENDS_WITH:
                     $where->where($key, 'LIKE', '%' . $value, $boolean);
                     break;
                 case BaseFilter::EQUALS:
                     $where->where($key, '=', $value, $boolean);
                     break;
                 case BaseFilter::NOT_EQUAL:
                     $where->where($key, '!=', $value, $boolean);
                     break;
             }
         }
     }
 }
开发者ID:LaravelRepository,项目名称:eloquent-repository,代码行数:68,代码来源:EloquentFilter.php

示例6: scopeBetweenDates

 /**
  * Gets events between two dates.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param \DateTime $startsAt
  * @param \DateTime $endsAt
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeBetweenDates($query, DateTime $startsAt, DateTime $endsAt)
 {
     return $query->whereBetween('starts_at', array($startsAt->copy()->setTime(0, 0, 0), $startsAt->copy()->setTime(23, 59, 59)))->where('ends_at', '<', $endsAt);
 }
开发者ID:larrytech,项目名称:calendar,代码行数:12,代码来源:Event.php

示例7: scopeFromDateTimeRange

 public function scopeFromDateTimeRange(Builder $query, $range, $exact = true)
 {
     if (!is_array($range)) {
         $range = DateTime::getDateTimeRange($range, $range, $exact);
     } else {
         $range = [(string) new Carbon($range[0]), (string) new Carbon($range[1])];
     }
     return $query->whereBetween('created_at', $range);
 }
开发者ID:DraperStudio,项目名称:Laravel-Database,代码行数:9,代码来源:DateTimeTrait.php

示例8: scopeToday

 /**
  * 查询今天的数据
  *
  * @param $query
  *
  * @return mixed
  */
 public function scopeToday(Builder $query)
 {
     return $query->whereBetween(static::CREATED_AT, [date('Y-m-d 00:00:00', time()), date('Y-m-d h:i:s', time())]);
 }
开发者ID:netxinyi,项目名称:meigui,代码行数:11,代码来源:BaseModel.php

示例9: whereBetween

 /**
  * Overwrite the whereBetween method to add the table name in front of the column
  *
  * @param $column
  * @param array $values
  * @param string $boolean
  * @param bool|false $not
  * @return mixed
  */
 public function whereBetween($column, array $values, $boolean = 'and', $not = false)
 {
     return parent::whereBetween($this->getModelTableColumn($column), $values, $boolean, $not);
 }
开发者ID:Jchedev,项目名称:laravel-evolved,代码行数:13,代码来源:Builder.php

示例10: _query

 /**
  * @param Builder $query
  * @param string  $field
  * @param string  $condition
  */
 protected function _query(Builder $query, $field, $condition = 'and')
 {
     $query->whereBetween($field, $this->getValue(), $condition);
 }
开发者ID:KodiComponents,项目名称:module-datasource,代码行数:9,代码来源:BetweenOperator.php

示例11: wherePeriod

 /**
  * Period query helper
  *
  * @param Builder               $query query builder
  * @param \DateTime|string      $since begin date
  * @param \DateTime|string|null $until end date
  * @return void
  */
 private function wherePeriod(Builder $query, $since, $until = null)
 {
     if ($until !== null) {
         $query->whereBetween($this->getTaggableTable() . '.createdAt', [$since, $until]);
     } else {
         $query->where($this->getTaggableTable() . '.createdAt', '>', $since);
     }
 }
开发者ID:xpressengine,项目名称:xpressengine,代码行数:16,代码来源:Tag.php

示例12: applyOperation

 /**
  * Append where for a Quri operation
  *
  * @param Builder $builder
  * @param Operation $operation
  * @param $andOr
  * @return Builder
  * @throws ValidationException
  */
 public function applyOperation($builder, Operation $operation, $andOr)
 {
     $fieldName = $this->getRealFieldName($operation->fieldName());
     switch ($operation->operator()) {
         case "eq":
             $symbol = "=";
             break;
         case "neq":
             $symbol = "!=";
             break;
         case "gt":
             $symbol = ">";
             break;
         case "lt":
             $symbol = "<";
             break;
         case "gte":
             $symbol = ">=";
             break;
         case "lte":
             $symbol = "<=";
             break;
         case "like":
             $symbol = "like";
             break;
         case "between":
             return $builder->whereBetween($fieldName, $operation->values(), $andOr);
         case "in":
             return $builder->whereIn($fieldName, $operation->values(), $andOr);
         case "nin":
             return $builder->whereNotIn($fieldName, $operation->values(), $andOr);
         default:
             throw new ValidationException("QURI string could not be parsed. Operator '{$operation->operator()}' not supported");
     }
     return $builder->where($fieldName, $symbol, $operation->firstValue(), $andOr);
 }
开发者ID:theHarvester,项目名称:QURI-Laravel,代码行数:45,代码来源:QuriRequest.php

示例13: setDateBetween

 /**
  * DateBetween
  *
  * @param $key
  * @param $value
  * @return $this
  */
 private function setDateBetween($key, $value)
 {
     $this->query->whereBetween(\DB::raw('DATE(' . $key . ')'), $value);
     return $this;
 }
开发者ID:aginev,项目名称:search-filters,代码行数:12,代码来源:Filter.php

示例14: registerMacro

 /**
  * 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);
 }
开发者ID:jarektkaczyk,项目名称:eloquent-scopes,代码行数:36,代码来源:Period.php

示例15: scopeSubMonth

 /**
  * Scope a query to only include activities that starts in a certain month.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query  the query to activities to be scoped
  * @param  int  $month  the number of months to be subtracted from the current month
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeSubMonth($query, $month = 0)
 {
     $query->whereBetween('datetime_start', [Carbon::now()->subMonth($month)->startOfMonth(), Carbon::now()->subMonth($month)->endOfMonth()]);
 }
开发者ID:jonnylow,项目名称:CrowdSourcingApplicationWeb,代码行数:11,代码来源:Activity.php


注:本文中的Illuminate\Database\Eloquent\Builder::whereBetween方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。