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


PHP Builder::orWhereHas方法代码示例

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


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

示例1: process

 protected function process()
 {
     $this->method = 'GET';
     //database save
     switch ($this->action) {
         case "search":
             // prepare the WHERE clause
             foreach ($this->fields as $field) {
                 $field->getValue();
                 $field->getNewValue();
                 $value = $field->new_value;
                 //query scope
                 $query_scope = $field->query_scope;
                 $query_scope_params = $field->query_scope_params;
                 if ($query_scope) {
                     if (is_a($query_scope, '\\Closure')) {
                         array_unshift($query_scope_params, $value);
                         array_unshift($query_scope_params, $this->query);
                         $this->query = call_user_func_array($query_scope, $query_scope_params);
                     } elseif (isset($this->model) && method_exists($this->model, "scope" . $query_scope)) {
                         $query_scope = "scope" . $query_scope;
                         array_unshift($query_scope_params, $value);
                         array_unshift($query_scope_params, $this->query);
                         $this->query = call_user_func_array([$this->model, $query_scope], $query_scope_params);
                     }
                     continue;
                 }
                 //detect if where should be deep (on relation)
                 $deep_where = false;
                 if (isset($this->model) && $field->relation != null) {
                     $rel_type = get_class($field->relation);
                     if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\HasOne') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\HasMany') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany')) {
                         if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') and in_array($field->type, array('select', 'radiogroup', 'autocomplete'))) {
                             $deep_where = false;
                         } else {
                             $deep_where = true;
                         }
                     }
                 }
                 if ($value != "" or is_array($value) and count($value)) {
                     if (strpos($field->name, "_copy") > 0) {
                         $name = substr($field->db_name, 0, strpos($field->db_name, "_copy"));
                     } else {
                         $name = $field->db_name;
                     }
                     //$value = $field->value;
                     if ($deep_where) {
                         //exception for multiple value fields on BelongsToMany
                         if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') and in_array($field->type, array('tags', 'checks', 'multiselect'))) {
                             $values = explode($field->serialization_sep, $value);
                             if ($field->clause == 'wherein') {
                                 $this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $values) {
                                     $q->whereIn($field->rel_fq_key, $values);
                                 });
                             }
                             if ($field->clause == 'where') {
                                 foreach ($values as $v) {
                                     $this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $v) {
                                         $q->where($field->rel_fq_key, '=', $v);
                                     });
                                 }
                             }
                             continue;
                         }
                         switch ($field->clause) {
                             case "like":
                                 $this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $value) {
                                     $q->where($field->rel_field, 'LIKE', '%' . $value . '%');
                                 });
                                 break;
                             case "orlike":
                                 $this->query = $this->query->orWhereHas($field->rel_name, function ($q) use($field, $value) {
                                     $q->where($field->rel_field, 'LIKE', '%' . $value . '%');
                                 });
                                 break;
                             case "where":
                                 $this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $value) {
                                     $q->where($field->rel_field, $field->operator, $value);
                                 });
                                 break;
                             case "orwhere":
                                 $this->query = $this->query->orWhereHas($field->rel_name, function ($q) use($field, $value) {
                                     $q->where($field->rel_field, $field->operator, $value);
                                 });
                                 break;
                             case "wherebetween":
                                 $values = explode($field->serialization_sep, $value);
                                 $this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $values) {
                                     if ($values[0] != '' and $values[1] == '') {
                                         $q->where($field->rel_field, ">=", $values[0]);
                                     } elseif ($values[0] == '' and $values[1] != '') {
                                         $q->where($field->rel_field, "<=", $values[1]);
                                     } elseif ($values[0] != '' and $values[1] != '') {
                                         //we avoid "whereBetween" because a bug in laravel 4.1
                                         $q->where(function ($query) use($field, $values) {
                                             return $query->where($field->rel_field, ">=", $values[0])->where($field->rel_field, "<=", $values[1]);
                                         });
                                     }
                                 });
                                 break;
//.........这里部分代码省略.........
开发者ID:maxmirazh33,项目名称:rapyd-laravel,代码行数:101,代码来源:DataFilter.php

示例2: buildWildcardQueryFilters

 /**
  * Build wildcard query filters.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  array  $fields
  * @param  array  $keyword
  * @param  string  $group
  *
  * @return void
  */
 protected function buildWildcardQueryFilters($query, array $fields, array $keyword = [])
 {
     foreach ($fields as $field) {
         if (Str::contains($field, '.') && $query instanceof Builder) {
             list($relation, $field) = explode('.', $field, 2);
             $query->orWhereHas($relation, function ($query) use($field, $keyword) {
                 $this->buildWildcardQueryFilterWithKeyword($query, $field, $keyword, 'where');
             });
         } else {
             $this->buildWildcardQueryFilterWithKeyword($query, $field, $keyword, 'orWhere');
         }
     }
 }
开发者ID:DavidIWilson,项目名称:site1,代码行数:23,代码来源:QueryFilterTrait.php


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