當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。