trait Illuminate / Database / Eloquent / Concerns / QueriesRelationships
You are viewing an older version of the documentation. For the latest, please visit master documentation.

QueriesRelationships

Methods

public

has ( $relation , $operator , $count , $boolean , Closure $callback ) : Builder |static

Add a relationship count / exists condition to the query.

Parameters

  • $relation Relation |string
  • $operator string
  • $count int
  • $boolean string
  • $callback Closure |null
protected

hasNested ( $relations , $operator , $count , $boolean , $callback ) : Builder |static

Add nested relationship count / exists conditions to the query.

Parameters

  • $relations string
  • $operator string
  • $count int
  • $boolean string
  • $callback Closure |null
public

orHas ( $relation , $operator , $count ) : Builder |static

Add a relationship count / exists condition to the query with an "or".

Parameters

  • $relation string
  • $operator string
  • $count int
public

doesntHave ( $relation , $boolean , Closure $callback ) : Builder |static

Add a relationship count / exists condition to the query.

Parameters

  • $relation string
  • $boolean string
  • $callback Closure |null
public

orDoesntHave ( $relation ) : Builder |static

Add a relationship count / exists condition to the query with an "or".

Parameters

  • $relation string
public

whereHas ( $relation , Closure $callback , $operator , $count ) : Builder |static

Add a relationship count / exists condition to the query with where clauses.

Parameters

  • $relation string
  • $callback Closure |null
  • $operator string
  • $count int
public

orWhereHas ( $relation , Closure $callback , $operator , $count ) : Builder |static

Add a relationship count / exists condition to the query with where clauses and an "or".

Parameters

  • $relation string
  • $callback Closure |null
  • $operator string
  • $count int
public

whereDoesntHave ( $relation , Closure $callback ) : Builder |static

Add a relationship count / exists condition to the query with where clauses.

Parameters

  • $relation string
  • $callback Closure |null
public

orWhereDoesntHave ( $relation , Closure $callback ) : Builder |static

Add a relationship count / exists condition to the query with where clauses and an "or".

Parameters

  • $relation string
  • $callback Closure |null
public

hasMorph ( $relation , $types , $operator , $count , $boolean , Closure $callback ) : Builder |static

Add a polymorphic relationship count / exists condition to the query.

Parameters

  • $relation MorphTo |string
  • $types string|array
  • $operator string
  • $count int
  • $boolean string
  • $callback Closure |null
protected

getBelongsToRelation ( MorphTo $relation , $type ) : BelongsTo

Get the BelongsTo relationship for a single polymorphic type.

Parameters

public

orHasMorph ( $relation , $types , $operator , $count ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with an "or".

Parameters

  • $relation MorphTo |string
  • $types string|array
  • $operator string
  • $count int
public

doesntHaveMorph ( $relation , $types , $boolean , Closure $callback ) : Builder |static

Add a polymorphic relationship count / exists condition to the query.

Parameters

  • $relation MorphTo |string
  • $types string|array
  • $boolean string
  • $callback Closure |null
public

orDoesntHaveMorph ( $relation , $types ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with an "or".

Parameters

  • $relation MorphTo |string
  • $types string|array
public

whereHasMorph ( $relation , $types , Closure $callback , $operator , $count ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with where clauses.

Parameters

  • $relation MorphTo |string
  • $types string|array
  • $callback Closure |null
  • $operator string
  • $count int
public

orWhereHasMorph ( $relation , $types , Closure $callback , $operator , $count ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".

Parameters

  • $relation MorphTo |string
  • $types string|array
  • $callback Closure |null
  • $operator string
  • $count int
public

whereDoesntHaveMorph ( $relation , $types , Closure $callback ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with where clauses.

Parameters

public

orWhereDoesntHaveMorph ( $relation , $types , Closure $callback ) : Builder |static

Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".

Parameters

public

whereRelation ( $relation , $column , $operator , $value ) : Builder |static

Add a basic where clause to a relationship query.

Parameters

public

orWhereRelation ( $relation , $column , $operator , $value ) : Builder |static

Add an "or where" clause to a relationship query.

Parameters

public

whereMorphRelation ( $relation , $types , $column , $operator , $value ) : Builder |static

Add a polymorphic relationship condition to the query with a where clause.

Parameters

public

orWhereMorphRelation ( $relation , $types , $column , $operator , $value ) : Builder |static

Add a polymorphic relationship condition to the query with an "or where" clause.

Parameters

public

whereMorphedTo ( $relation , $model , $boolean ) : Builder |static

Add a morph-to relationship condition to the query.

Parameters

public

orWhereMorphedTo ( $relation , $model ) : Builder |static

Add a morph-to relationship condition to the query with an "or where" clause.

Parameters

public

whereBelongsTo ( $related , $relationshipName , $boolean ) : $this

Add a "belongs to" relationship where clause to the query.

Parameters

  • $related Model
  • $relationship string
  • $boolean string
public

orWhereBelongsTo ( $related , $relationshipName ) : $this

Add an "BelongsTo" relationship with an "or where" clause to the query.

Parameters

  • $related Model
  • $relationship string
public

withAggregate ( $relations , $column , $function ) : $this

Add subselect queries to include an aggregate value for a relationship.

Parameters

  • $relations mixed
  • $column string
  • $function string
public

withCount ( $relations ) : $this

Add subselect queries to count the relations.

Parameters

  • $relations mixed
public

withMax ( $relation , $column ) : $this

Add subselect queries to include the max of the relation's column.

Parameters

  • $relation string|array
  • $column string
public

withMin ( $relation , $column ) : $this

Add subselect queries to include the min of the relation's column.

Parameters

  • $relation string|array
  • $column string
public

withSum ( $relation , $column ) : $this

Add subselect queries to include the sum of the relation's column.

Parameters

  • $relation string|array
  • $column string
public

withAvg ( $relation , $column ) : $this

Add subselect queries to include the average of the relation's column.

Parameters

  • $relation string|array
  • $column string
public

withExists ( $relation ) : $this

Add subselect queries to include the existence of related models.

Parameters

  • $relation string|array
protected

addHasWhere ( Builder $hasQuery , Relation $relation , $operator , $count , $boolean ) : Builder |static

Add the "has" condition where clause to the query.

Parameters

public

mergeConstraintsFrom ( Builder $from ) : Builder |static

Merge the where constraints from another query to the current query.

Parameters

protected

addWhereCountQuery ( Builder $query , $operator , $count , $boolean ) : $this

Add a sub-query count clause to this query.

Parameters

  • $query Builder
  • $operator string
  • $count int
  • $boolean string
protected

getRelationWithoutConstraints ( $relation ) : Relation

Get the "has relation" base query instance.

Parameters

  • $relation string
protected

canUseExistsForExistenceCheck ( $operator , $count ) : bool

Check if we can run an "exists" query to optimize performance.

Parameters

  • $operator string
  • $count int