has() public method

Add a relationship count / exists condition to the query.
public has ( string $relation, string $operator = '>=', integer $count = 1, string $boolean = 'and', Closure $callback = null ) : Builder | static
$relation string
$operator string
$count integer
$boolean string
$callback Closure
return Builder | static
コード例 #1
0
ファイル: User.php プロジェクト: kolexndr/mustard
 /**
  * Scope of sellers.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeSellers($query)
 {
     return $query->has('items');
 }
コード例 #2
0
ファイル: Translatable.php プロジェクト: jaffle-be/framework
 /**
  * @param Builder $builder
  * @return Builder|static
  */
 public function scopeTranslated(Builder $builder)
 {
     return $builder->has('translations');
 }
コード例 #3
0
 /**
  * Scope for a Model that doesn't have any tags.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeWithoutTags(Builder $query)
 {
     return $query->has('tags', '=', 0);
 }
コード例 #4
0
 public function scopeWithAnyTags(Builder $query, $tags = [])
 {
     $tags = Util::buildTagArray($tags);
     if (empty($tags)) {
         return $query->has('tags');
     }
     $slug = array_map([S::class, 'slugify'], $tags);
     return $query->whereHas('tags', function ($q) use($slug) {
         $q->whereIn('slug', $slug);
     });
 }
コード例 #5
0
ファイル: Role.php プロジェクト: larrytech/auth
 /**
  * Gets the roles with no users.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeInactive($query)
 {
     return $query->has('users', '<', 1);
 }
コード例 #6
0
 public function scopeActive(Builder $query)
 {
     $query->has('attributeOptions');
 }
コード例 #7
0
ファイル: Category.php プロジェクト: kolexndr/mustard
 /**
  * Scope of categories with no children.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeLeaves($query)
 {
     return $query->has('children', 0);
 }
コード例 #8
0
 public function apply(Builder $builder, Model $model)
 {
     $builder->has('article');
     $this->addWithDrafts($builder);
 }
コード例 #9
0
ファイル: Has.php プロジェクト: czim/laravel-repository
 /**
  * @param Builder $model
  * @return mixed
  */
 public function applyToQuery($model)
 {
     return $model->has($this->relation, $this->operator, $this->count, $this->boolean, $this->callback);
 }
コード例 #10
0
 /**
  * Query has relations.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  array                                 $hasRelations
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function queryHasRelations($query, $hasRelations = [])
 {
     $hasRelations = $hasRelations ?: $this->hasRelations;
     foreach ($hasRelations as $relation => $operatorCount) {
         list($operator, $count) = $operatorCount;
         $query->has($relation, $operator, $count);
     }
     return $query;
 }
コード例 #11
0
 /**
  * @param User $actor
  * @param Builder $query
  */
 public function find(User $actor, Builder $query)
 {
     // Hide discussions which have tags that the user is not allowed to see.
     $query->whereNotExists(function ($query) use($actor) {
         return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))->where('discussions.id', new Expression('discussion_id'));
     });
     // Hide discussions with no tags if the user doesn't have that global
     // permission.
     if (!$actor->hasPermission('viewDiscussions')) {
         $query->has('tags');
     }
 }
コード例 #12
0
ファイル: Player.php プロジェクト: apolune/account
 /**
  * Scope a query to only include online players.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeOnline($query)
 {
     return $query->has('playerOnline');
 }
コード例 #13
0
 /**
  * @param Builder $query
  * @param UserInterface $user
  * @return Builder
  */
 public function scopeForUser(Builder $query, UserInterface $user = null)
 {
     if ($user === null && $this->user !== null) {
         $user = $this->user;
     }
     if ($user === null) {
         return $query->has('activities');
     }
     return $query->whereHas('activities', function ($q) use($user) {
         $q->where('user_id', '=', $user->getAuthIdentifier());
     });
 }
コード例 #14
0
 /**
  * Query wether or not the relationship is empty of now.
  *
  * @param        $relation
  * @param string $operator
  * @param int    $count
  *
  * @return $this
  */
 public function has($relation, $operator = '>=', $count = 1)
 {
     $this->builder = $this->builder->has($relation, $operator, $count);
     return $this;
 }
コード例 #15
0
 /**
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder|static
  */
 public function scopeTranslated(Builder $query)
 {
     return $query->has('translations');
 }
コード例 #16
0
 /**
  * @param Builder $query
  *
  * @return Builder
  */
 public function scopeInStock(Builder $query) : Builder
 {
     return $query->has('availableStock');
 }
コード例 #17
0
ファイル: _ide_helper.php プロジェクト: satriashp/tour
 /**
  * Add a relationship count condition to the query.
  *
  * @param string $relation
  * @param string $operator
  * @param int $count
  * @param string $boolean
  * @param \Closure|null $callback
  * @return \Illuminate\Database\Eloquent\Builder|static 
  * @static 
  */
 public static function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
 {
     return \Illuminate\Database\Eloquent\Builder::has($relation, $operator, $count, $boolean, $callback);
 }
コード例 #18
0
 /**
  * get has a minimum one published child element of category
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param string $relation
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeHasPublishedElement($query, $relation)
 {
     return $query->has($relation, '>=', 1, 'and', function ($query) {
         return $query->published();
     });
 }