QueriesRelationships
trait QueriesRelationships mixin Builder
Methods
Add a relationship count / exists condition to the query.
Add nested relationship count / exists conditions to the query.
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.
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".
Add a polymorphic relationship count / exists condition to the query.
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 a basic where clause to a relationship query and eager-load the relationship with the same conditions.
Add an "or where" clause to a relationship query.
Add a basic count / exists condition 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 polymorphic relationship condition to the query with a doesn't have clause.
Add a polymorphic relationship condition to the query with an "or doesn't have" 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.
Resolve the morph type for a relationship query.
Add a "belongs to" relationship where clause to the query.
Add a "BelongsTo" relationship with an "or where" clause to the query.
Add a "belongs to many" relationship where clause to the query.
Add a "belongs to many" 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.
Ensure a relationship constraint does not carry a statement-level timeout.
Get the "has relation" base query instance.
Check if we can run an "exists" query to optimize performance.
Details
at line 42
QueriesRelationships
has(Relation|string $relation, string $operator = '>=', Expression|int $count = 1, string $boolean = 'and', Closure|null $callback = null)
Add a relationship count / exists condition to the query.
at line 93
protected QueriesRelationships
hasNested(string $relations, string $operator = '>=', Expression|int $count = 1, string $boolean = 'and', Closure|null $callback = null)
Add nested relationship count / exists conditions to the query.
Set up recursive calls to has until we finish the nested relation.
at line 115
QueriesRelationships
orHas(Relation|string $relation, string $operator = '>=', Expression|int $count = 1)
Add a relationship count / exists condition to the query with an "or".
at line 128
QueriesRelationships
doesntHave(Relation|string $relation, string $boolean = 'and', Closure|null $callback = null)
Add a relationship count / exists condition to the query.
at line 138
QueriesRelationships
orDoesntHave(Relation|string $relation)
Add a relationship count / exists condition to the query with an "or".
at line 151
QueriesRelationships
whereHas(Relation|string $relation, Closure|null $callback = null, string $operator = '>=', Expression|int $count = 1)
Add a relationship count / exists condition to the query with where clauses.
at line 163
QueriesRelationships
withWhereHas(string $relation, Closure|null $callback = null, string $operator = '>=', Expression|int $count = 1)
Add a relationship count / exists condition to the query with where clauses.
Also load the relationship with the same condition.
at line 177
QueriesRelationships
orWhereHas(Relation|string $relation, Closure|null $callback = null, string $operator = '>=', Expression|int $count = 1)
Add a relationship count / exists condition to the query with where clauses and an "or".
at line 190
QueriesRelationships
whereDoesntHave(Relation|string $relation, Closure|null $callback = null)
Add a relationship count / exists condition to the query with where clauses.
at line 203
QueriesRelationships
orWhereDoesntHave(Relation|string $relation, Closure|null $callback = null)
Add a relationship count / exists condition to the query with where clauses and an "or".
at line 217
QueriesRelationships
hasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', Expression|int $count = 1, string $boolean = 'and', Closure|null $callback = null)
Add a polymorphic relationship count / exists condition to the query.
at line 292
protected BelongsTo
getBelongsToRelation(MorphTo $relation, string $type)
Get the BelongsTo relationship for a single polymorphic type.
at line 314
QueriesRelationships
orHasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', Expression|int $count = 1)
Add a polymorphic relationship count / exists condition to the query with an "or".
at line 328
QueriesRelationships
doesntHaveMorph(MorphTo|string $relation, string|array $types, string $boolean = 'and', Closure|null $callback = null)
Add a polymorphic relationship count / exists condition to the query.
at line 339
QueriesRelationships
orDoesntHaveMorph(MorphTo|string $relation, string|array $types)
Add a polymorphic relationship count / exists condition to the query with an "or".
at line 353
QueriesRelationships
whereHasMorph(MorphTo|string $relation, string|array $types, Closure|null $callback = null, string $operator = '>=', Expression|int $count = 1)
Add a polymorphic relationship count / exists condition to the query with where clauses.
at line 367
QueriesRelationships
orWhereHasMorph(MorphTo|string $relation, string|array $types, Closure|null $callback = null, string $operator = '>=', Expression|int $count = 1)
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
at line 381
QueriesRelationships
whereDoesntHaveMorph(MorphTo|string $relation, string|array $types, Closure|null $callback = null)
Add a polymorphic relationship count / exists condition to the query with where clauses.
at line 395
QueriesRelationships
orWhereDoesntHaveMorph(MorphTo|string $relation, string|array $types, Closure|null $callback = null)
Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
at line 408
QueriesRelationships
whereRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a basic where clause to a relationship query.
at line 422
QueriesRelationships
withWhereRelation(string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a basic where clause to a relationship query and eager-load the relationship with the same conditions.
at line 440
QueriesRelationships
orWhereRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add an "or where" clause to a relationship query.
at line 459
QueriesRelationships
whereDoesntHaveRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add a basic count / exists condition to a relationship query.
at line 478
QueriesRelationships
orWhereDoesntHaveRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)
Add an "or where" clause to a relationship query.
at line 498
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.
at line 514
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.
at line 530
QueriesRelationships
whereMorphDoesntHaveRelation(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 doesn't have clause.
at line 546
QueriesRelationships
orWhereMorphDoesntHaveRelation(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 doesn't have" clause.
at line 562
QueriesRelationships
whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a morph-to relationship condition to the query.
at line 607
QueriesRelationships
whereNotMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a not morph-to relationship condition to the query.
at line 652
QueriesRelationships
orWhereMorphedTo(MorphTo|string $relation, mixed $model)
Add a morph-to relationship condition to the query with an "or where" clause.
at line 663
QueriesRelationships
orWhereNotMorphedTo(MorphTo|string $relation, mixed $model)
Add a not morph-to relationship condition to the query with an "or where" clause.
at line 673
protected string
getMorphTypeForQuery(string $model)
Resolve the morph type for a relationship query.
at line 698
QueriesRelationships
whereBelongsTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to" relationship where clause to the query.
at line 738
QueriesRelationships
orWhereBelongsTo(mixed $related, string|null $relationshipName = null)
Add a "BelongsTo" relationship with an "or where" clause to the query.
at line 751
QueriesRelationships
whereAttachedTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to many" relationship where clause to the query.
at line 789
QueriesRelationships
orWhereAttachedTo(mixed $related, string|null $relationshipName = null)
Add a "belongs to many" relationship with an "or where" clause to the query.
at line 797
QueriesRelationships
withAggregate(mixed $relations, Expression|string $column, string|null $function = null)
Add subselect queries to include an aggregate value for a relationship.
at line 899
protected string
getRelationHashedColumn(string $column, Relation $relation)
Get the relation hashed column name for the given column and relation.
at line 913
QueriesRelationships
withCount(mixed $relations)
Add subselect queries to count the relations.
at line 921
QueriesRelationships
withMax(string|array $relation, Expression|string $column)
Add subselect queries to include the max of the relation's column.
at line 929
QueriesRelationships
withMin(string|array $relation, Expression|string $column)
Add subselect queries to include the min of the relation's column.
at line 937
QueriesRelationships
withSum(string|array $relation, Expression|string $column)
Add subselect queries to include the sum of the relation's column.
at line 945
QueriesRelationships
withAvg(string|array $relation, Expression|string $column)
Add subselect queries to include the average of the relation's column.
at line 953
QueriesRelationships
withExists(string|array $relation)
Add subselect queries to include the existence of related models.
at line 964
protected QueriesRelationships
addHasWhere(Builder $hasQuery, Relation $relation, string $operator, Expression|int $count, string $boolean)
Add the "has" condition where clause to the query.
at line 981
QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
at line 1008
protected array
requalifyWhereTables(array $wheres, string $from, string $to)
Updates the table name for any columns with a new qualified name.
at line 1022
protected QueriesRelationships
addWhereCountQuery(Builder $query, string $operator = '>=', Expression|int $count = 1, string $boolean = 'and')
Add a sub-query count clause to this query.
at line 1039
protected void
ensureNoTimeoutOnRelationshipConstraint(Builder $query)
Ensure a relationship constraint does not carry a statement-level timeout.
at line 1053
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
at line 1063
protected bool
canUseExistsForExistenceCheck(string $operator, Expression|int $count)
Check if we can run an "exists" query to optimize performance.