Illuminate\Database\Eloquent\Builder::has PHP Метод

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
    public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
    {
        if (strpos($relation, '.') !== false) {
            return $this->hasNested($relation, $operator, $count, $boolean, $callback);
        }
        $relation = $this->getHasRelationQuery($relation);
        // If we only need to check for the existence of the relation, then we can
        // optimize the subquery to only run a "where exists" clause instead of
        // the full "count" clause. This will make the query run much faster.
        $queryType = $this->shouldRunExistsQuery($operator, $count) ? 'getRelationQuery' : 'getRelationCountQuery';
        $query = $relation->{$queryType}($relation->getRelated()->newQuery(), $this);
        if ($callback) {
            $query->callScope($callback);
        }
        return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
    }

Usage Example

Пример #1
0
 /**
  * Scope of sellers.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeSellers($query)
 {
     return $query->has('items');
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::has