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


PHP Builder::whereBetween方法代码示例

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


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

示例1: setDateSearchQuery

 /**
  * Process DATE type of query
  * @param Builder $query
  * @param string $key
  * @param array $values
  */
 protected function setDateSearchQuery($query, $key, array $values)
 {
     $arrValues = $values['values'];
     switch ($values['operator']) {
         case '=':
             if (isset(static::$searchParams[$key]['relation'])) {
                 $relationKey = static::$searchParams[$key]['relation'][1];
                 $query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $arrValues) {
                     $q->where($relationKey, 'LIKE', "%{$arrValues[0]}%");
                 });
             } else {
                 $query->where($key, 'LIKE', "%{$values['values'][0]}%");
             }
             break;
         case '>=':
         case '<=':
             if (isset(static::$searchParams[$key]['relation'])) {
                 $relationKey = static::$searchParams[$key]['relation'][1];
                 $operator = $values['operator'];
                 $query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $operator, $arrValues) {
                     $q->where($relationKey, $operator, "{$arrValues[0]}");
                 });
             } else {
                 $query->where($key, $values['operator'], "{$values['values'][0]}");
             }
             break;
         case '><':
             if (isset(static::$searchParams[$key]['relation'])) {
                 $relationKey = static::$searchParams[$key]['relation'][1];
                 $query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $arrValues) {
                     $q->whereBetween($relationKey, $arrValues);
                 });
             } else {
                 $query->whereBetween($key, $arrValues);
             }
             break;
     }
 }
开发者ID:andrewboy,项目名称:search-box,代码行数:44,代码来源:SearchTrait.php

示例2: metaQueryClause

 /**
  * @param  array   $queries  {
  *
  * @type string    $relation Optional. The MySQL keyword used to join the clauses of the query. Accepts 'AND', Or
  *       'OR'. Default 'AND'.
  *
  * @type array {
  * @type string    $key      Meta key to filter by.
  * @type string    $value    Meta value to filter by.
  * @type string    $compare  MySQL operator used for comparing the $value. Accepts '=',
  *                               '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN',
  *                               'BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', or 'RLIKE'.
  *                               Default is '='
  *             }
  * }
  *
  * @param  Builder $q
  * @param  int     $depth
  */
 public function metaQueryClause($queries, &$q, $depth = 0)
 {
     $i = 0;
     foreach ($queries as $key => $query) {
         if ('relation' === $key) {
             //if relation were found we shall skip to the next iteration
             continue;
         } else {
             if (isset($query['key'])) {
                 // That happens when a non-nested query found on the first iteration
                 // in that case we the clause should be AND
                 $relation = 0 === $i ? 'AND' : $queries['relation'];
                 $q->where(function ($q) use($query) {
                     if (isset($query['key'])) {
                         $q->where('meta_key', '=', $query['key']);
                     }
                     if (isset($query['value'])) {
                         if (isset($query['compare'])) {
                             switch (strtolower($query['compare'])) {
                                 case 'between':
                                     $q->whereBetween('meta_value', $query['value']);
                                     break;
                                 case 'not between':
                                     $q->whereNotBetween('meta_value', $query['value']);
                                     break;
                                 case 'in':
                                     $q->whereIn('meta_value', $query['value']);
                                     break;
                                 case 'not in':
                                     $q->whereNotIn('meta_value', $query['value']);
                                     break;
                                 case 'is null':
                                     $q->whereIsNull('meta_value');
                                     break;
                                 case 'is not null':
                                     $q->whereIsNotNull('meta_value');
                                     break;
                                 default:
                                     $q->where('meta_value', $query['compare'], $query['value']);
                             }
                         } else {
                             $q->where('meta_value', '=', $query['value']);
                         }
                     }
                 }, null, null, $relation);
             } else {
                 if (is_array($query)) {
                     $depth = $depth + 1;
                     // If we're going recursive for the first iterate we shall make the relation AND by default
                     // else we should use the provided relation
                     $relation = 1 === $depth && 0 === $i ? 'AND' : $queries['relation'];
                     $q->where(function ($q) use($query, $depth) {
                         $this->metaQueryClause($query, $q, $depth);
                     }, null, null, $relation);
                 } else {
                     continue;
                 }
             }
         }
         $i++;
     }
 }
开发者ID:puresolcom,项目名称:polyether,代码行数:81,代码来源:MetaQuery.php


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