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


PHP Builder::whereHas方法代码示例

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


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

示例1: scopeWithTag

 public static function scopeWithTag(Builder $query, $tags, $type = 'slug')
 {
     $tags = (new static())->prepareTags($tags);
     return $query->whereHas('tags', function ($query) use($type, $tags) {
         $query->whereIn($type, $tags);
     });
 }
开发者ID:phantomlight,项目名称:programme-chameleon,代码行数:7,代码来源:TaggableTrait.php

示例2: scopeVisible

 /**
  * @param Builder|\Illuminate\Database\Eloquent\Builder|Model $query
  * @return mixed
  */
 public function scopeVisible($query)
 {
     return $query->whereHas('profile', function ($query) {
         /** @var Profile $query */
         return $query->visible();
     });
 }
开发者ID:productionEA,项目名称:pockeyt-api,代码行数:11,代码来源:Post.php

示例3: scopeHasActiveDiary

 /**
  * アクティブな日誌があるか
  * @param Builder $query
  * @param $cropId
  * @return Builder|static
  */
 public function scopeHasActiveDiary(Builder $query, $cropId = null)
 {
     return $query->whereHas('workDiaries', function ($query) use($cropId) {
         $query->where('archive', false);
         if (!is_null($cropId)) {
             $query->where('crop_id', $cropId);
         }
     });
 }
开发者ID:nana4rider,项目名称:mdiary,代码行数:15,代码来源:WorkField.php

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

示例5: scopeFilter

 /**
  * query filter with id scope
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeFilter($query, $request)
 {
     // filter id
     if ($request->has('id')) {
         $query->where('id', $request->get('id'));
     }
     // filter title
     if ($request->has('title')) {
         $query->where('title', 'like', "%{$request->get('title')}%");
     }
     // filter category
     if ($request->has('category')) {
         $query->whereHas('category', function ($query) use($request) {
             $query->where('name', 'like', "%{$request->get('category')}%");
         });
     }
     // filter status
     if ($request->has('status')) {
         $query->where('is_publish', $request->get('status'));
     }
     // filter created_at
     if ($request->has('created_at_from')) {
         $query->where('created_at', '>=', Carbon::parse($request->get('created_at_from')));
     }
     if ($request->has('created_at_to')) {
         $query->where('created_at', '<=', Carbon::parse($request->get('created_at_to')));
     }
     return $query;
 }
开发者ID:erenmustafaozdal,项目名称:laravel-page-module,代码行数:36,代码来源:Page.php

示例6: constrainWhereIsAll

 /**
  * Constrain the given users query by all provided roles.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string  $role
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function constrainWhereIsAll($query, $role)
 {
     $roles = array_slice(func_get_args(), 1);
     return $query->whereHas('roles', function ($query) use($roles) {
         $query->whereIn('name', $roles);
     }, '=', count($roles));
 }
开发者ID:jonagoldman,项目名称:bouncer,代码行数:14,代码来源:Roles.php

示例7: apply

 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  * @param \Illuminate\Database\Eloquent\Model   $model
  */
 public function apply(Builder $builder, Model $model)
 {
     $builder->whereHas('meta', function ($query) {
         $query->where('meta_key', '_apiposts_enable_api_key')->where('meta_value', 'yes');
         self::$apiEnabledScopeColumn = $query->toSql();
     });
 }
开发者ID:PrafullaKumarSahu,项目名称:example-plugin,代码行数:13,代码来源:ApiEnabledScope.php

示例8: scopeFormed

 /**
  * Scope a query to only include guilds that are fully formed.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeFormed(Builder $query)
 {
     return $query->whereHas('memberships', function ($membership) {
         $membership->whereHas('rank', function ($rank) {
             $rank->where('level', '>', 1);
         });
     }, '>=', 4);
 }
开发者ID:apolune,项目名称:guilds,代码行数:14,代码来源:Guild.php

示例9: apply

 /**
  * Apply scope on the query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @param  \Illuminate\Database\Eloquent\Model $model
  *
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     $column = $model->getApplicationForeignKey(true);
     $builder->whereHas('applications', function ($q) use($column) {
         $q->where($column, CurrentApplication::get()->id);
     });
     $this->addAllApplications($builder);
 }
开发者ID:ryzr,项目名称:core,代码行数:16,代码来源:hasManyApplicationsScope.php

示例10: apply

 /**
  * @param Builder $builder
  * @param Model   $model
  */
 public function apply(Builder $builder, Model $model)
 {
     if (!Auth::guest() && Auth::user()->hasCountryRole()) {
         $country = Auth::user()->country;
         if ($builder->getModel()->getTable() == "activity_logs") {
             $builder->whereHas('contract', function ($q) use($country) {
                 $q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
             });
         } elseif ($builder->getModel()->getTable() == "contract_annotations") {
             $builder->whereHas('contract', function ($q) use($country) {
                 $q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
             });
         } else {
             $builder->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
         }
     }
 }
开发者ID:sadhakbj,项目名称:resourcecontracts.org,代码行数:21,代码来源:CountryScope.php

示例11: apply

 public function apply(Builder $builder, Model $model)
 {
     $account = Account::getCurrent();
     if (isset($account)) {
         $builder->whereHas('account', function ($query) use($account) {
             $query->where('accounts.id', $account->id);
         });
     }
 }
开发者ID:rogerapras,项目名称:app_veiculos,代码行数:9,代码来源:TenantScope.php

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

示例13: apply

 /**
  * Applies constraint to query.
  *
  * @param Builder $builder query builder
  * @param string  $field   field name
  * @param string  $mode    determines how constraint is added to existing query ("or" or "and")
  */
 public function apply(Builder $builder, $field, $mode = Constraint::MODE_AND)
 {
     if ($this->isRelation($field)) {
         list($relation, $field) = $this->splitRelationField($field);
         $builder->whereHas($relation, function (Builder $builder) use($field, $mode) {
             $this->doApply($builder, $field, $mode);
         });
     } else {
         $this->doApply($builder, $field, $mode);
     }
 }
开发者ID:nbulaienko,项目名称:laravel-searchable,代码行数:18,代码来源:Constraint.php

示例14: queryRelations

 /**
  * @param Builder $query
  * @param $column
  * @param $value
  */
 private function queryRelations(Builder $query, $column, $value)
 {
     list($relation_name, $column) = explode('.', $column, 2);
     if (!is_array($value)) {
         $query->whereHas($relation_name, function ($subQuery) use($column, $value) {
             $subQuery->where($column, 'like', "%{$value}%");
         });
     } else {
         //TODO: debatable
     }
 }
开发者ID:team-ccsad,项目名称:project-101,代码行数:16,代码来源:EloquentFilterable.php

示例15: scopeFilter

 /**
  * Restrict the resource to the given filters.
  * These are the main functionalities:
  * 
  *   - Scope on the (single) relation!
  *     Use "-" as delimeter between the resource name and attribute.
  *     > /v1/items?article:drug_amount=1000mg
  *
  *   - Use different operators!
  *     Use one of the operators as first character in the value.
  *     > /v1/items?article:cost=]5
  *     > /v1/items?article:cost=[20
  *     > /v1/items?article:name=~panadol
  *     
  *   - It now uses byCedric/Inquiry package!
  * 
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  array  $values  (default: array())
  * @param  string $relation_delimeter  (default: -)
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeFilter($query, array $values = array())
 {
     // all allowed attributes
     $attributes = array_keys($this->getArrayableItems(array_merge($this->attributes, array_flip($this->visible))));
     // itterate over the provided queries
     foreach ($values as $key => $value) {
         // set some main variables
         $inquiry = Inquiry::get($key);
         $operator = null;
         $relation = null;
         $method = null;
         // check if a valid operator was supplied
         if (!$inquiry->hasOperator() && !$inquiry->hasRange()) {
             continue;
         }
         // check if the key is a filterable attribute
         if (!in_array($inquiry->getKey(), $attributes)) {
             // if it doesn't has a relation, it's definitly not the good attribute
             if (!$inquiry->swap()->hasRelation()) {
                 continue;
             }
             // get the relation, with the key (func:attr) as main value
             $relation = $inquiry->swap()->getRelation();
             $method = camel_case($relation->getRelated());
             // check if the relation is allowed
             if (!method_exists($this, $method) || !in_array($method, $attributes)) {
                 continue;
             }
         }
         // check if the operator is a range query
         if ($inquiry->hasRange()) {
             // get the range values
             $operator = $inquiry->getRange();
         } else {
             // get the operator query
             $operator = $inquiry->getOperator();
         }
         // if a relation was provided
         if ($relation !== null) {
             // apply relation query
             $query->whereHas($method, function ($query) use($operator, $relation) {
                 // apply final query
                 $this->applyQuery($query, $relation->getValue(), $operator);
             });
             // query already applied
             continue;
         }
         // apply query
         $this->applyQuery($query, $inquiry->getKey(), $operator);
     }
     // return the query for method chaining
     return $query;
 }
开发者ID:peakfijn,项目名称:get-some-rest,代码行数:74,代码来源:ResourceFilteringScopeTrait.php


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