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.
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.
Get the "has relation" base query instance.
Check if we can run an "exists" query to optimize performance.
Details
at line 39
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 90
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.
Sets up recursive call to whereHas until we finish the nested relation.
at line 127
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 140
QueriesRelationships
doesntHave(Relation|string $relation, string $boolean = 'and', Closure|null $callback = null)
Add a relationship count / exists condition to the query.
at line 150
QueriesRelationships
orDoesntHave(Relation|string $relation)
Add a relationship count / exists condition to the query with an "or".
at line 163
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 175
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 189
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 202
QueriesRelationships
whereDoesntHave(Relation|string $relation, Closure|null $callback = null)
Add a relationship count / exists condition to the query with where clauses.
at line 215
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 229
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 290
protected BelongsTo
getBelongsToRelation(MorphTo $relation, string $type)
Get the BelongsTo relationship for a single polymorphic type.
at line 312
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 326
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 337
QueriesRelationships
orDoesntHaveMorph(MorphTo|string $relation, string|array $types)
Add a polymorphic relationship count / exists condition to the query with an "or".
at line 351
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 365
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 379
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 393
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 406
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(Relation|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 559
QueriesRelationships
whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a morph-to relationship condition to the query.
at line 605
QueriesRelationships
whereNotMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a not morph-to relationship condition to the query.
at line 649
QueriesRelationships
orWhereMorphedTo(MorphTo|string $relation, mixed $model)
Add a morph-to relationship condition to the query with an "or where" clause.
at line 660
QueriesRelationships
orWhereNotMorphedTo(MorphTo|string $relation, mixed $model)
Add a not morph-to relationship condition to the query with an "or where" clause.
at line 672
QueriesRelationships
whereBelongsTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to" relationship where clause to the query.
at line 714
QueriesRelationships
orWhereBelongsTo(mixed $related, string|null $relationshipName = null)
Add a "BelongsTo" relationship with an "or where" clause to the query.
at line 726
QueriesRelationships
whereAttachedTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to many" relationship where clause to the query.
at line 764
QueriesRelationships
orWhereAttachedTo(mixed $related, string|null $relationshipName = null)
Add a "belongs to many" relationship with an "or where" clause to the query.
at line 772
QueriesRelationships
withAggregate(mixed $relations, Expression|string $column, string|null $function = null)
Add subselect queries to include an aggregate value for a relationship.
at line 873
protected string
getRelationHashedColumn(string $column, Relation $relation)
Get the relation hashed column name for the given column and relation.
at line 887
QueriesRelationships
withCount(mixed $relations)
Add subselect queries to count the relations.
at line 895
QueriesRelationships
withMax(string|array $relation, Expression|string $column)
Add subselect queries to include the max of the relation's column.
at line 903
QueriesRelationships
withMin(string|array $relation, Expression|string $column)
Add subselect queries to include the min of the relation's column.
at line 911
QueriesRelationships
withSum(string|array $relation, Expression|string $column)
Add subselect queries to include the sum of the relation's column.
at line 919
QueriesRelationships
withAvg(string|array $relation, Expression|string $column)
Add subselect queries to include the average of the relation's column.
at line 927
QueriesRelationships
withExists(string|array $relation)
Add subselect queries to include the existence of related models.
at line 938
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 952
QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
at line 979
protected array
requalifyWhereTables(array $wheres, string $from, string $to)
Updates the table name for any columns with a new qualified name.
at line 993
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 1010
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
at line 1020
protected bool
canUseExistsForExistenceCheck(string $operator, Expression|int $count)
Check if we can run an "exists" query to optimize performance.