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


PHP Builder::whereHas方法代码示例

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


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

示例1: whereHas

 /**
  * 关联查询
  * @param $relation
  * @param \Closure $callback 由于此处 Closure 接受的参数是 Table 类,所以下面调用时封装了一次
  * @return static
  */
 public function whereHas($relation, $callback)
 {
     $this->original->whereHas($relation, function ($query) use($callback) {
         call_user_func($callback, lego_table($query));
     });
     return $this;
 }
开发者ID:wutongwan,项目名称:laravel-lego,代码行数:13,代码来源:EloquentTable.php

示例2: scopeTagged

 /**
  * Get things tagged with all of a given comma-separated list of tags.
  * @param \Illuminate\Database\Query\Builder $query
  * @param string $tagged
  */
 public function scopeTagged($query, $tagged)
 {
     foreach (explode(',', $tagged) as $tag) {
         $query->whereHas('tags', function ($query) use($tag) {
             $query->where('name', $tag);
         });
     }
     return $query;
 }
开发者ID:samwilson,项目名称:asset-manager,代码行数:14,代码来源:Taggable.php

示例3: deleteByCategory

 /**
  * Delete All notifications from a
  * defined category
  *
  * @param $category_name int
  * @param $expired Bool
  * @return Bool
  */
 public function deleteByCategory($category_name, $expired = false)
 {
     $query = $this->notification->whereHas('body', function ($q) use($category_name) {
         $q->where('name', $category_name);
     });
     if ($expired == true) {
         return $query->onlyExpired()->delete();
     }
     return $query->delete();
 }
开发者ID:naimkhalifa,项目名称:Notifynder,代码行数:18,代码来源:NotificationRepository.php

示例4: 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

示例5: scopeWhichRoles

 /**
  * Take user by roles.
  *
  * @param \Illuminate\Database\Query\Builder $query
  * @param string|array $roles
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeWhichRoles($query, $roles)
 {
     return $query->whereHas('roles', function ($query) use($roles) {
         $roles = is_array($roles) ? $roles : [$roles];
         $query->whereIn('name', $roles);
     });
 }
开发者ID:torome,项目名称:defender,代码行数:15,代码来源:HasRoles.php

示例6: whereHas

 /**
  * 关联查询
  * @param $relation
  * @param $callback
  * @return static
  */
 public function whereHas($relation, $callback)
 {
     $this->original->whereHas($relation, $callback);
     return $this;
 }
开发者ID:zhwei,项目名称:laravel-lego,代码行数:11,代码来源:EloquentTable.php

示例7: buildWhereHas

 /**
  * @param Builder|QueryBuilder $queryBuilder
  * @param $hasField
  * @param $operator
  * @param $value
  * @param string $boolean
  */
 protected function buildWhereHas($queryBuilder, $hasField, $operator, $value, $boolean = 'and')
 {
     $reversedParts = explode('.', strrev($hasField), 2);
     $hasField = strrev($reversedParts[1]);
     $field = strrev($reversedParts[0]);
     $queryBuilder->whereHas($hasField, function ($query) use($queryBuilder, $field, $operator, $value, $boolean) {
         $this->buildWhere($query, $field, $operator, $value, $boolean);
     });
 }
开发者ID:williamoliveira,项目名称:eloquent-array-query-builder,代码行数:16,代码来源:ArrayBuilder.php


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