QueriesRelationships
trait QueriesRelationships (View source)
Methods
Add a relationship count / exists condition to the query with an "or".
Add a relationship count / exists condition to the query.
Add a relationship count / exists condition to the query with an "or".
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with where clauses and an "or".
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with where clauses and an "or".
Get the BelongsTo relationship for a single polymorphic type.
Add a polymorphic relationship count / exists condition to the query with an "or".
Add a polymorphic relationship count / exists condition to the query.
Add a polymorphic relationship count / exists condition to the query with an "or".
Add a polymorphic relationship count / exists condition to the query with where clauses.
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
Add a polymorphic relationship count / exists condition to the query with where clauses.
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
Add a basic where clause to a relationship query.
Add an "or where" clause to a relationship query.
Add a polymorphic relationship condition to the query with a where clause.
Add a polymorphic relationship condition to the query with an "or where" clause.
Add a morph-to relationship condition to the query.
Add a not morph-to relationship condition to the query.
Add a morph-to relationship condition to the query with an "or where" clause.
Add a not morph-to relationship condition to the query with an "or where" clause.
Add a "belongs to" relationship where clause to the query.
Add an "BelongsTo" relationship with an "or where" clause to the query.
Add subselect queries to include an aggregate value for a relationship.
Get the relation hashed column name for the given column and relation.
Add subselect queries to count the relations.
Add subselect queries to include the max of the relation's column.
Add subselect queries to include the min of the relation's column.
Add subselect queries to include the sum of the relation's column.
Add subselect queries to include the average of the relation's column.
Add subselect queries to include the existence of related models.
Add the "has" condition where clause to the query.
Merge the where constraints from another query to the current query.
Updates the table name for any columns with a new qualified name.
Add a sub-query count clause to this query.
Get the "has relation" base query instance.
Check if we can run an "exists" query to optimize performance.
Details
Builder|QueriesRelationships
has(Relation|string $relation, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)
Add a relationship count / exists condition to the query.
protected Builder|QueriesRelationships
hasNested(string $relations, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure|null $callback = null)
Add nested relationship count / exists conditions to the query.
Sets up recursive call to whereHas until we finish the nested relation.
Builder|QueriesRelationships
orHas(string $relation, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with an "or".
Builder|QueriesRelationships
doesntHave(string $relation, string $boolean = 'and', Closure $callback = null)
Add a relationship count / exists condition to the query.
Builder|QueriesRelationships
orDoesntHave(string $relation)
Add a relationship count / exists condition to the query with an "or".
Builder|QueriesRelationships
whereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with where clauses.
Builder|QueriesRelationships
withWhereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with where clauses.
Also load the relationship with same condition.
Builder|QueriesRelationships
orWhereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with where clauses and an "or".
Builder|QueriesRelationships
whereDoesntHave(string $relation, Closure $callback = null)
Add a relationship count / exists condition to the query with where clauses.
Builder|QueriesRelationships
orWhereDoesntHave(string $relation, Closure $callback = null)
Add a relationship count / exists condition to the query with where clauses and an "or".
Builder|QueriesRelationships
hasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)
Add a polymorphic relationship count / exists condition to the query.
protected BelongsTo
getBelongsToRelation(MorphTo $relation, string $type)
Get the BelongsTo relationship for a single polymorphic type.
Builder|QueriesRelationships
orHasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', int $count = 1)
Add a polymorphic relationship count / exists condition to the query with an "or".
Builder|QueriesRelationships
doesntHaveMorph(MorphTo|string $relation, string|array $types, string $boolean = 'and', Closure $callback = null)
Add a polymorphic relationship count / exists condition to the query.
Builder|QueriesRelationships
orDoesntHaveMorph(MorphTo|string $relation, string|array $types)
Add a polymorphic relationship count / exists condition to the query with an "or".
Builder|QueriesRelationships
whereHasMorph(MorphTo|string $relation, string|array $types, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a polymorphic relationship count / exists condition to the query with where clauses.
Builder|QueriesRelationships
orWhereHasMorph(MorphTo|string $relation, string|array $types, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
Builder|QueriesRelationships
whereDoesntHaveMorph(MorphTo|string $relation, string|array $types, Closure $callback = null)
Add a polymorphic relationship count / exists condition to the query with where clauses.
Builder|QueriesRelationships
orWhereDoesntHaveMorph(MorphTo|string $relation, string|array $types, Closure $callback = null)
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
Builder|QueriesRelationships
whereRelation(string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a basic where clause to a relationship query.
Builder|QueriesRelationships
orWhereRelation(string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add an "or where" clause to a relationship query.
Builder|QueriesRelationships
whereMorphRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a polymorphic relationship condition to the query with a where clause.
Builder|QueriesRelationships
orWhereMorphRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a polymorphic relationship condition to the query with an "or where" clause.
Builder|QueriesRelationships
whereMorphedTo(MorphTo|string $relation, Model|string $model, $boolean = 'and')
Add a morph-to relationship condition to the query.
Builder|QueriesRelationships
whereNotMorphedTo(MorphTo|string $relation, Model|string $model, $boolean = 'and')
Add a not morph-to relationship condition to the query.
Builder|QueriesRelationships
orWhereMorphedTo(MorphTo|string $relation, Model|string $model)
Add a morph-to relationship condition to the query with an "or where" clause.
Builder|QueriesRelationships
orWhereNotMorphedTo(MorphTo|string $relation, Model|string $model)
Add a not morph-to relationship condition to the query with an "or where" clause.
$this
whereBelongsTo(Model|Model> $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to" relationship where clause to the query.
$this
orWhereBelongsTo(Model $related, string|null $relationshipName = null)
Add an "BelongsTo" relationship with an "or where" clause to the query.
$this
withAggregate(mixed $relations, string $column, string $function = null)
Add subselect queries to include an aggregate value for a relationship.
protected string
getRelationHashedColumn(string $column, Relationship $relation)
Get the relation hashed column name for the given column and relation.
$this
withCount(mixed $relations)
Add subselect queries to count the relations.
$this
withMax(string|array $relation, string $column)
Add subselect queries to include the max of the relation's column.
$this
withMin(string|array $relation, string $column)
Add subselect queries to include the min of the relation's column.
$this
withSum(string|array $relation, string $column)
Add subselect queries to include the sum of the relation's column.
$this
withAvg(string|array $relation, string $column)
Add subselect queries to include the average of the relation's column.
$this
withExists(string|array $relation)
Add subselect queries to include the existence of related models.
protected Builder|QueriesRelationships
addHasWhere(Builder $hasQuery, Relation $relation, string $operator, int $count, string $boolean)
Add the "has" condition where clause to the query.
Builder|QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
protected array
requalifyWhereTables(array $wheres, string $from, string $to)
Updates the table name for any columns with a new qualified name.
protected $this
addWhereCountQuery(Builder $query, string $operator = '>=', int $count = 1, string $boolean = 'and')
Add a sub-query count clause to this query.
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
protected bool
canUseExistsForExistenceCheck(string $operator, int $count)
Check if we can run an "exists" query to optimize performance.