has() 공개 메소드

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
리턴 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
 /**
  * @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);
 }
 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
 /**
  * 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
 /**
  * @param Builder $model
  * @return mixed
  */
 public function applyToQuery($model)
 {
     return $model->has($this->relation, $this->operator, $this->count, $this->boolean, $this->callback);
 }
 /**
  * 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
 /**
  * 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);
 }
 /**
  * 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();
     });
 }