W3cubDocs

/Laravel 5.8

QueriesRelationships

trait QueriesRelationships (View source)

Methods

Builder|QueriesRelationships has(string|Relation $relation, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)

Add a relationship count / exists condition to the query.

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.

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 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(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.

BelongsTo getBelongsToRelation(MorphTo $relation, string $type)

Get the BelongsTo relationship for a single polymorphic type.

Builder|QueriesRelationships orHasMorph(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(string $relation, string|array $types, string $boolean = 'and', Closure $callback = null)

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

Builder|QueriesRelationships orDoesntHaveMorph(string $relation, string|array $types)

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

Builder|QueriesRelationships whereHasMorph(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(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(string $relation, string|array $types, Closure $callback = null)

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

Builder|QueriesRelationships orWhereDoesntHaveMorph(string $relation, string|array $types, Closure $callback = null)

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

$this withCount(mixed $relations)

Add subselect queries to count the relations.

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.

$this addWhereCountQuery(Builder $query, string $operator = '>=', int $count = 1, string $boolean = 'and')

Add a sub-query count clause to this query.

Relation getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

bool canUseExistsForExistenceCheck(string $operator, int $count)

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

Details

Builder|QueriesRelationships has(string|Relation $relation, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)

Add a relationship count / exists condition to the query.

Parameters

string|Relation $relation
string $operator
int $count
string $boolean
Closure $callback

Return Value

Builder|QueriesRelationships

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.

Parameters

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

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orHas(string $relation, string $operator = '>=', int $count = 1)

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

Parameters

string $relation
string $operator
int $count

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships doesntHave(string $relation, string $boolean = 'and', Closure $callback = null)

Add a relationship count / exists condition to the query.

Parameters

string $relation
string $boolean
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orDoesntHave(string $relation)

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

Parameters

string $relation

Return Value

Builder|QueriesRelationships

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.

Parameters

string $relation
Closure $callback
string $operator
int $count

Return Value

Builder|QueriesRelationships

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".

Parameters

string $relation
Closure $callback
string $operator
int $count

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships whereDoesntHave(string $relation, Closure $callback = null)

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

Parameters

string $relation
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereDoesntHave(string $relation, Closure $callback = null)

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

Parameters

string $relation
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships hasMorph(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.

Parameters

string $relation
string|array $types
string $operator
int $count
string $boolean
Closure $callback

Return Value

Builder|QueriesRelationships

protected BelongsTo getBelongsToRelation(MorphTo $relation, string $type)

Get the BelongsTo relationship for a single polymorphic type.

Parameters

MorphTo $relation
string $type

Return Value

BelongsTo

Builder|QueriesRelationships orHasMorph(string $relation, string|array $types, string $operator = '>=', int $count = 1)

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

Parameters

string $relation
string|array $types
string $operator
int $count

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships doesntHaveMorph(string $relation, string|array $types, string $boolean = 'and', Closure $callback = null)

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

Parameters

string $relation
string|array $types
string $boolean
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orDoesntHaveMorph(string $relation, string|array $types)

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

Parameters

string $relation
string|array $types

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships whereHasMorph(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.

Parameters

string $relation
string|array $types
Closure $callback
string $operator
int $count

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereHasMorph(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".

Parameters

string $relation
string|array $types
Closure $callback
string $operator
int $count

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships whereDoesntHaveMorph(string $relation, string|array $types, Closure $callback = null)

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

Parameters

string $relation
string|array $types
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereDoesntHaveMorph(string $relation, string|array $types, Closure $callback = null)

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

Parameters

string $relation
string|array $types
Closure $callback

Return Value

Builder|QueriesRelationships

$this withCount(mixed $relations)

Add subselect queries to count the relations.

Parameters

mixed $relations

Return Value

$this

protected Builder|QueriesRelationships addHasWhere(Builder $hasQuery, Relation $relation, string $operator, int $count, string $boolean)

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

Parameters

Builder $hasQuery
Relation $relation
string $operator
int $count
string $boolean

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships mergeConstraintsFrom(Builder $from)

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

Parameters

Builder $from

Return Value

Builder|QueriesRelationships

protected $this addWhereCountQuery(Builder $query, string $operator = '>=', int $count = 1, string $boolean = 'and')

Add a sub-query count clause to this query.

Parameters

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

Return Value

$this

protected Relation getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

Parameters

string $relation

Return Value

Relation

protected bool canUseExistsForExistenceCheck(string $operator, int $count)

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

Parameters

string $operator
int $count

Return Value

bool

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.8/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.html