Builder
class Builder implements Builder mixin Builder<int,
Forwarded query methods operate on this builder, so their value type is TModel.
Keep toBase() and getQuery() unparameterized because raw queries return stdClass rows.
Traits
Unlike Laravel, this declares no @mixin Builder: Builder is its only user, and the bare mixin made
PHPStan accept on every builder whatever the builder of an unknown model accepts.
Properties
| protected Builder | $query | The base query builder instance. |
|
| protected TModel | $model | The model being queried. |
|
| array | $pendingAttributes | The attributes that should be added to new models created by this builder. |
|
| protected array | $eagerLoad | The relationships that should be eager loaded. |
|
| static protected array | $macros | All of the globally registered builder macros. |
|
| protected array | $localMacros | All of the locally registered builder macros. |
|
| protected Closure|null | $onDelete | A replacement for the typical delete function. |
|
| protected list<string> | $propertyPassthru | The properties that should be returned from query builder. |
|
| protected list<string> | $passthru | The methods that should be returned from query builder. |
|
| protected array | $scopes | Applied global scopes. |
|
| protected array | $removedScopes | Removed global scopes. |
|
| protected Closure> | $afterQueryCallbacks | The callbacks that should be invoked after retrieving data from the database. |
|
| protected Closure> | $onCloneCallbacks | The callbacks that should be invoked on clone. |
|
| $this|HigherOrderBuilderProxy read-only | $orWhere | ||
| $this|HigherOrderBuilderProxy read-only | $whereNot | ||
| $this|HigherOrderBuilderProxy read-only | $orWhereNot |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Run a map over each item while chunking.
Execute a callback over each item while chunking.
Chunk the results of a query by comparing IDs.
Chunk the results of a query by comparing IDs in descending order.
Chunk the results of a query by comparing IDs in a given order.
Execute a callback over each item while chunking by ID.
Query lazily, by chunks of the given size.
Query lazily, by chunking the results of a query by comparing IDs.
Query lazily, by chunking the results of a query by comparing IDs in descending order.
Query lazily, by chunking the results of a query by comparing IDs in a given order.
Get the ID of the last result of a chunk to continue paging from.
Prepare the last chunk ID for comparison with the paging column.
Get the model attribute behind a qualified paging column.
Execute the query and get the first result.
Execute the query and get the first result or throw an exception.
Execute the query and get the first result if it's the sole matching record.
Paginate the given query using a cursor paginator.
Get the builder that owns cursor binding and page execution.
Get a cursor parameter for database binding.
Get the original column name of the given column, without any aliasing.
Determine whether the resolved cursor column is a declared SQL expression.
Create a new length-aware paginator instance.
Create a new simple paginator instance.
Create a new cursor paginator instance.
Pass the query to a given callback and then return it.
Pass the query to a given callback and return the result.
Forward a method call to the given object.
Forward a method call to the given object, returning $this if the forwarded call returned itself.
Throw a bad method call exception for the given method.
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.
Remove all or passed registered global scopes.
Remove all global scopes except the given scopes.
Get an array of global scopes that were removed from the query.
Add a where clause on the primary key to the query.
Add a where clause on the primary key to the query.
Add an "or where" clause on the primary key to the query.
Add an "or where not" clause on the primary key to the query.
Add a basic where clause to the query, and return the first result.
Add an "or where not" clause to the query.
Create a collection of models from plain arrays.
Insert into the database after merging the model's default attributes, setting timestamps, and casting values.
Insert (ignoring errors) into the database after merging the model's default attributes, setting timestamps, and casting values.
Insert a record into the database and get its ID after merging the model's default attributes, setting timestamps, and casting values.
Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values.
Create a collection of models from a raw query.
Find a model by its primary key.
Find a model by its primary key or throw an exception.
Find a model by its primary key or return fresh model instance.
Get the first record matching the attributes or instantiate it.
Get the first record matching the attributes. If the record is not found, create it.
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
Validate first-or-create and create-or-first operations, including relationship calls.
Create or update a record matching the attributes, and fill it with values.
Create a record matching the attributes, or increment the existing record.
Get a single column's value from the first result of a query if it's the sole matching record.
Get a single column's value from the first result of the query or throw an exception.
Get the selected value through the model's attribute accessors.
Execute the query as a "select" statement.
Get the hydrated models without eager loading.
Eager load the relationships for the models.
Eagerly load the relationship on a set of models.
Get the relation instance for the given relation name.
Get the deeply nested relations for a given top-level relation.
Determine if the relationship is nested.
Get a lazy collection for the given query.
Add a generic "order by" clause if the query doesn't already have one.
Get a collection with the values of a given column.
Get an array of primary keys from the query result.
Paginate the given query into a simple paginator.
Paginate the given query into a cursor paginator.
Ensure the proper order by required for cursor pagination.
Save a new model and return the instance without raising model events.
Save a new model and return the instance. Allow mass-assignment.
Save a new model instance with mass assignment without raising model events.
Update records in the database.
Update records in a PostgreSQL database using the update from syntax.
Insert new records or update the existing ones.
Update the column's update timestamp.
Increment a column's value by a given amount.
Decrement a column's value by a given amount.
Increment the given column's values by the given amounts.
Decrement the given column's values by the given amounts.
Add the "updated at" column to an array of values.
Add unique IDs to the inserted values.
Add timestamps to the inserted values.
Add the "updated at" column to the updated columns.
Delete records from the database.
Run the default delete function on the builder.
Determine if the given model has a scope.
Call the given local model scopes.
Apply the scopes to the Eloquent builder instance and return it.
Apply a scope callback to the query.
Apply the given scope on the current builder instance.
Apply the given named scope on the current builder instance.
Nest where conditions by slicing them at the given where count.
Slice where conditions at the given offset and add them to the query as a nested condition.
Create a where array with nested where conditions.
Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
Create a new instance of the model being queried.
Parse a list of relations into individuals.
Prepare nested with relationships.
Combine an array of constraints into a single constraint.
Parse the attribute select constraints from the name.
Create a constraint to select the given columns for the relation.
Parse the nested relationships in a relation.
Specify attributes that should be added to any new models created by this builder.
Execute the given Closure within a transaction savepoint if needed.
Get the Eloquent builder instances that are used in the union of the query.
Get the relationships being eagerly loaded.
Set the relationships being eagerly loaded.
Indicate that the given relationships should not be eagerly loaded.
Flush the relationships being eagerly loaded.
Get the "limit" value from the query or null if it's not set.
Get the "offset" value from the query or null if it's not set.
Get the default key name of the table.
Qualify the given columns with the model's table.
Get the alias or table name that qualifies the query's source columns.
Checks if a macro is registered.
Get the given global macro by name.
Checks if a global macro is registered.
Flush all static state.
Dynamically access builder proxies.
Dynamically handle calls into the query instance.
Dynamically handle calls into the query instance.
Register the given mixin with the builder.
Clone the Eloquent query builder without the given query properties.
Clone the Eloquent query builder without the given query bindings.
Force a clone of the underlying query builder when cloning.
No description
No description
No description
No description
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
BuildsQueries at line 45
bool
chunk(int $count, callable $callback)
Chunk the results of the query.
in
BuildsQueries at line 101
Collection
chunkMap(callable $callback, int $count = 1000)
Run a map over each item while chunking.
in
BuildsQueries at line 119
bool
each(callable $callback, int $count = 1000)
Execute a callback over each item while chunking.
in
BuildsQueries at line 137
bool
chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null)
Chunk the results of a query by comparing IDs.
in
BuildsQueries at line 147
bool
chunkByIdDesc(int $count, callable $callback, string|null $column = null, string|null $alias = null)
Chunk the results of a query by comparing IDs in descending order.
in
BuildsQueries at line 157
bool
orderedChunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)
Chunk the results of a query by comparing IDs in a given order.
in
BuildsQueries at line 230
bool
eachById(callable $callback, int $count = 1000, string|null $column = null, string|null $alias = null)
Execute a callback over each item while chunking by ID.
in
BuildsQueries at line 248
LazyCollection
lazy(int $chunkSize = 1000)
Query lazily, by chunks of the given size.
in
BuildsQueries at line 301
LazyCollection
lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
Query lazily, by chunking the results of a query by comparing IDs.
in
BuildsQueries at line 311
LazyCollection
lazyByIdDesc(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
Query lazily, by chunking the results of a query by comparing IDs in descending order.
in
BuildsQueries at line 324
protected LazyCollection
orderedLazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)
Query lazily, by chunking the results of a query by comparing IDs in a given order.
in
BuildsQueries at line 392
protected mixed
getLastIdFromChunk(mixed $result, string $alias)
Get the ID of the last result of a chunk to continue paging from.
in
BuildsQueries at line 407
protected mixed
getNextPageIdFromChunk(mixed $result, string $column, string $alias)
Prepare the last chunk ID for comparison with the paging column.
in
BuildsQueries at line 425
protected string
getPagingAttribute(Model $model, string $column)
Get the model attribute behind a qualified paging column.
in
BuildsQueries at line 447
null|TValue
first(array|string $columns = ['*'])
Execute the query and get the first result.
at line 800
Model
firstOrFail(array|string $columns = ['*'])
Execute the query and get the first result or throw an exception.
at line 841
Model
sole(array|string $columns = ['*'])
Execute the query and get the first result if it's the sole matching record.
in
BuildsQueries at line 499
protected CursorPaginator
paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)
Paginate the given query using a cursor paginator.
at line 1239
protected Builder
getBuilderForCursorPage()
Get the builder that owns cursor binding and page execution.
at line 1254
protected mixed
getCursorParameterBinding(Cursor $cursor, string $parameter)
Get a cursor parameter for database binding.
in
BuildsQueries at line 579
protected string
getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)
Get the original column name of the given column, without any aliasing.
in
BuildsQueries at line 604
protected bool
isCursorExpression(Builder $query, string $parameter, string $original)
Determine whether the resolved cursor column is a declared SQL expression.
in
BuildsQueries at line 629
protected LengthAwarePaginator
paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
Create a new length-aware paginator instance.
in
BuildsQueries at line 639
protected Paginator
simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)
Create a new simple paginator instance.
in
BuildsQueries at line 649
protected CursorPaginator
cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)
Create a new cursor paginator instance.
in
BuildsQueries at line 662
BuildsQueries
tap(callable $callback)
Pass the query to a given callback and then return it.
in
BuildsQueries at line 677
TReturn is null|TReturn)
pipe(callable $callback)
Pass the query to a given callback and return the result.
in
ForwardsCalls at line 22
protected mixed
forwardCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object.
in
ForwardsCalls at line 52
protected mixed
forwardDecoratedCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object, returning $this if the forwarded call returned itself.
in
ForwardsCalls at line 66
static protected never
throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
in
QueriesRelationships at line 46
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.
in
QueriesRelationships at line 97
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.
in
QueriesRelationships at line 120
QueriesRelationships
orHas(Relation|string $relation, string $operator = '>=', Expression|int $count = 1)
Add a relationship count / exists condition to the query with an "or".
in
QueriesRelationships at line 134
QueriesRelationships
doesntHave(Relation|string $relation, string $boolean = 'and', Closure|null $callback = null)
Add a relationship count / exists condition to the query.
in
QueriesRelationships at line 145
QueriesRelationships
orDoesntHave(Relation|string $relation)
Add a relationship count / exists condition to the query with an "or".
in
QueriesRelationships at line 159
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.
in
QueriesRelationships at line 172
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.
in
QueriesRelationships at line 193
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".
in
QueriesRelationships at line 207
QueriesRelationships
whereDoesntHave(Relation|string $relation, Closure|null $callback = null)
Add a relationship count / exists condition to the query with where clauses.
in
QueriesRelationships at line 221
QueriesRelationships
orWhereDoesntHave(Relation|string $relation, Closure|null $callback = null)
Add a relationship count / exists condition to the query with where clauses and an "or".
in
QueriesRelationships at line 236
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.
in
QueriesRelationships at line 311
protected BelongsTo
getBelongsToRelation(MorphTo $relation, string $type)
Get the BelongsTo relationship for a single polymorphic type.
in
QueriesRelationships at line 336
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".
in
QueriesRelationships at line 351
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.
in
QueriesRelationships at line 363
QueriesRelationships
orDoesntHaveMorph(MorphTo|string $relation, string|array $types)
Add a polymorphic relationship count / exists condition to the query with an "or".
in
QueriesRelationships at line 378
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.
in
QueriesRelationships at line 393
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".
in
QueriesRelationships at line 408
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.
in
QueriesRelationships at line 423
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".
in
QueriesRelationships at line 437
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.
in
QueriesRelationships at line 453
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.
in
QueriesRelationships at line 472
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.
in
QueriesRelationships at line 492
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.
in
QueriesRelationships at line 512
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.
in
QueriesRelationships at line 533
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.
in
QueriesRelationships at line 550
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.
in
QueriesRelationships at line 567
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.
in
QueriesRelationships at line 584
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.
in
QueriesRelationships at line 601
QueriesRelationships
whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a morph-to relationship condition to the query.
in
QueriesRelationships at line 651
QueriesRelationships
whereNotMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a not morph-to relationship condition to the query.
in
QueriesRelationships at line 700
QueriesRelationships
orWhereMorphedTo(MorphTo|string $relation, mixed $model)
Add a morph-to relationship condition to the query with an "or where" clause.
in
QueriesRelationships at line 712
QueriesRelationships
orWhereNotMorphedTo(MorphTo|string $relation, mixed $model)
Add a not morph-to relationship condition to the query with an "or where" clause.
in
QueriesRelationships at line 722
protected string
getMorphTypeForQuery(string $model)
Resolve the morph type for a relationship query.
in
QueriesRelationships at line 748
QueriesRelationships
whereBelongsTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to" relationship where clause to the query.
in
QueriesRelationships at line 791
QueriesRelationships
orWhereBelongsTo(mixed $related, string|null $relationshipName = null)
Add a "BelongsTo" relationship with an "or where" clause to the query.
in
QueriesRelationships at line 805
QueriesRelationships
whereAttachedTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')
Add a "belongs to many" relationship where clause to the query.
in
QueriesRelationships at line 846
QueriesRelationships
orWhereAttachedTo(mixed $related, string|null $relationshipName = null)
Add a "belongs to many" relationship with an "or where" clause to the query.
in
QueriesRelationships at line 856
QueriesRelationships
withAggregate(mixed $relations, Expression|string $column, string|null $function = null)
Add subselect queries to include an aggregate value for a relationship.
in
QueriesRelationships at line 958
protected string
getRelationHashedColumn(string $column, Relation $relation)
Get the relation hashed column name for the given column and relation.
in
QueriesRelationships at line 974
QueriesRelationships
withCount(mixed $relations)
Add subselect queries to count the relations.
in
QueriesRelationships at line 984
QueriesRelationships
withMax(string|array $relation, Expression|string $column)
Add subselect queries to include the max of the relation's column.
in
QueriesRelationships at line 994
QueriesRelationships
withMin(string|array $relation, Expression|string $column)
Add subselect queries to include the min of the relation's column.
in
QueriesRelationships at line 1004
QueriesRelationships
withSum(string|array $relation, Expression|string $column)
Add subselect queries to include the sum of the relation's column.
in
QueriesRelationships at line 1014
QueriesRelationships
withAvg(string|array $relation, Expression|string $column)
Add subselect queries to include the average of the relation's column.
in
QueriesRelationships at line 1024
QueriesRelationships
withExists(string|array $relation)
Add subselect queries to include the existence of related models.
in
QueriesRelationships at line 1036
protected QueriesRelationships
addHasWhere(Builder $hasQuery, Relation $relation, string $operator, Expression|int $count, string $boolean)
Add the "has" condition where clause to the query.
in
QueriesRelationships at line 1054
QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
in
QueriesRelationships at line 1079
protected array
requalifyWhereTables(array $wheres, string $from, string $to)
Updates the table name for any columns with a new qualified name.
in
QueriesRelationships at line 1095
protected QueriesRelationships
addWhereCountQuery(Builder $query, string $operator = '>=', Expression|int $count = 1, string $boolean = 'and')
Add a sub-query count clause to this query.
in
QueriesRelationships at line 1112
protected void
ensureNoTimeoutOnRelationshipConstraint(Builder $query)
Ensure a relationship constraint does not carry a statement-level timeout.
in
QueriesRelationships at line 1126
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
in
QueriesRelationships at line 1136
protected bool
canUseExistsForExistenceCheck(string $operator, Expression|int $count)
Check if we can run an "exists" query to optimize performance.
at line 184
__construct(Builder $query)
Create a new Eloquent query builder instance.
at line 194
Model
make(array $attributes = [])
Create and return an un-saved model instance.
at line 204
Builder
withGlobalScope(int|string $identifier, Closure|Scope $scope)
Register a new global scope.
at line 238
Builder
withoutGlobalScopes(array|null $scopes = null)
Remove all or passed registered global scopes.
at line 256
Builder
withoutGlobalScopesExcept(array $scopes = [])
Remove all global scopes except the given scopes.
at line 268
array
removedScopes()
Get an array of global scopes that were removed from the query.
at line 278
Builder
whereKey(mixed $id, string $boolean = 'and', bool $not = false)
Add a where clause on the primary key to the query.
at line 312
Builder
whereKeyNot(mixed $id, string $boolean = 'and')
Add a where clause on the primary key to the query.
at line 322
Builder
orWhereKey(mixed $id)
Add an "or where" clause on the primary key to the query.
at line 332
Builder
orWhereKeyNot(mixed $id)
Add an "or where not" clause on the primary key to the query.
at line 340
Builder
except(mixed $models)
Exclude the given models from the query results.
at line 355
Builder
where(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
at line 380
Model|null
firstWhere(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query, and return the first result.
at line 394
Builder
orWhere(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null)
Add an "or where" clause to the query.
A null operator passed as the second of two arguments becomes a comparison with null, which makes a callback a subquery, so the callback type cannot follow the operator here.
at line 411
Builder
whereNot(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic "where not" clause to the query.
at line 428
Builder
orWhereNot(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null)
Add an "or where not" clause to the query.
at line 438
Builder
latest(Closure|Builder|Builder|Relation|Expression|string|null $column = null)
Add an "order by" clause for a timestamp to the query.
at line 458
Builder
oldest(Closure|Builder|Builder|Relation|Expression|string|null $column = null)
Add an "order by" clause for a timestamp to the query.
at line 478
Collection
hydrate(array $items)
Create a collection of models from plain arrays.
at line 498
bool
fillAndInsert(array $values)
Insert into the database after merging the model's default attributes, setting timestamps, and casting values.
at line 508
int
fillAndInsertOrIgnore(array $values)
Insert (ignoring errors) into the database after merging the model's default attributes, setting timestamps, and casting values.
at line 518
int
fillAndInsertGetId(array $values)
Insert a record into the database and get its ID after merging the model's default attributes, setting timestamps, and casting values.
at line 529
array
fillForInsert(array $values)
Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values.
at line 556
Collection
fromQuery(string $query, array $bindings = [])
Create a collection of models from a raw query.
at line 568
Model|Collection|null
find(mixed $id, array|string $columns = ['*'])
Find a model by its primary key.
at line 585
Model
findSole(mixed $id, array|string $columns = ['*'])
Find a sole model by its primary key.
at line 595
Collection
findMany(Arrayable|array $ids, array|string $columns = ['*'])
Find multiple models by their primary keys.
at line 613
Model|Collection
findOrFail(mixed $id, array|string $columns = ['*'])
Find a model by its primary key or throw an exception.
at line 651
Model|Collection
findOrNew(mixed $id, array|string $columns = ['*'])
Find a model by its primary key or return fresh model instance.
at line 675
mixed
findOr(mixed $id, Closure|array|string $columns = ['*'], Closure|null $callback = null)
Find a model by its primary key or call a callback.
at line 710
Model
firstOrNew(array $attributes = [], Closure|array $values = [])
Get the first record matching the attributes or instantiate it.
at line 725
Model
firstOrCreate(array $attributes = [], Closure|array $values = [])
Get the first record matching the attributes. If the record is not found, create it.
at line 744
Model
createOrFirst(array $attributes = [], Closure|array $values = [])
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
at line 760
void
ensureCanCreateOrFirst()
Validate first-or-create and create-or-first operations, including relationship calls.
Helpers delegate to each other, so this may run more than once per operation; keep overrides side-effect-free.
at line 770
Model
updateOrCreate(array $attributes, Closure|array $values = [])
Create or update a record matching the attributes, and fill it with values.
at line 784
Model
incrementOrCreate(array $attributes, string $column = 'count', float|int $default = 1, float|int $step = 1, array $extra = [])
Create a record matching the attributes, or increment the existing record.
at line 818
mixed
firstOr(Closure|array $columns = ['*'], Closure|null $callback = null)
Execute the query and get the first result or call a callback.
at line 853
mixed
value(Expression|string $column)
Get a single column's value from the first result of a query.
at line 868
mixed
soleValue(Expression|string $column)
Get a single column's value from the first result of a query if it's the sole matching record.
at line 878
mixed
valueOrFail(Expression|string $column)
Get a single column's value from the first result of the query or throw an exception.
at line 886
protected mixed
getValueFromModel(Model $model, Expression|string $column)
Get the selected value through the model's attribute accessors.
at line 902
Collection
get(array|string $columns = ['*'])
Execute the query as a "select" statement.
at line 923
array
getModels(array|string $columns = ['*'])
Get the hydrated models without eager loading.
at line 936
array
eagerLoadRelations(array $models)
Eager load the relationships for the models.
at line 953
protected array
eagerLoadRelation(array $models, string $name, Closure $constraints)
Eagerly load the relationship on a set of models.
at line 979
Relation
getRelation(string $name)
Get the relation instance for the given relation name.
at line 1007
protected array
relationsNestedUnder(string $relation)
Get the deeply nested relations for a given top-level relation.
at line 1026
protected bool
isNestedUnder(string $relation, string $name)
Determine if the relationship is nested.
at line 1036
Builder
afterQuery(Closure $callback)
Register a closure to be invoked after the query is executed.
at line 1053
Collection
applyAfterQueryCallbacks(Collection $result)
Invoke the "after query" modification callbacks.
A callback that replaces the collection type owns the resulting type change.
at line 1067
LazyCollection
cursor()
Get a lazy collection for the given query.
at line 1083
protected void
enforceOrderBy()
Add a generic "order by" clause if the query doesn't already have one.
at line 1099
Collection
pluck(Expression|string $column, string|null $key = null)
Get a collection with the values of a given column.
at line 1135
array
modelKeys()
Get an array of primary keys from the query result.
at line 1149
LengthAwarePaginator
paginate(Closure|int|null $perPage = null, array|string $columns = ['*'], string $pageName = 'page', int|null $page = null, Closure|int|null $total = null)
Paginate the given query.
at line 1172
Paginator
simplePaginate(int|null $perPage = null, array|string $columns = ['*'], string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
at line 1194
CursorPaginator
cursorPaginate(int|null $perPage = null, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)
Paginate the given query into a cursor paginator.
at line 1204
protected Collection
ensureOrderForCursorPagination(bool $shouldReverse = false)
Ensure the proper order by required for cursor pagination.
at line 1267
Model
create(array $attributes = [])
Save a new model and return the instance.
at line 1279
Model
createQuietly(array $attributes = [])
Save a new model and return the instance without raising model events.
at line 1289
Model
forceCreate(array $attributes)
Save a new model and return the instance. Allow mass-assignment.
at line 1301
Model
forceCreateQuietly(array $attributes = [])
Save a new model instance with mass assignment without raising model events.
at line 1309
int
update(array $values)
Update records in the database.
at line 1317
int
updateFrom(array $values)
Update records in a PostgreSQL database using the update from syntax.
at line 1325
int
upsert(array $values, array|string $uniqueBy, array|null $update = null)
Insert new records or update the existing ones.
at line 1349
false|int
touch(array|string|null $column = null)
Update the column's update timestamp.
at line 1373
int
increment(Expression|string $column, mixed $amount = 1, array $extra = [])
Increment a column's value by a given amount.
at line 1385
int
decrement(Expression|string $column, mixed $amount = 1, array $extra = [])
Decrement a column's value by a given amount.
at line 1400
int
incrementEach(array $columns, array $extra = [])
Increment the given column's values by the given amounts.
at line 1414
int
decrementEach(array $columns, array $extra = [])
Decrement the given column's values by the given amounts.
at line 1425
protected array
addUpdatedAtColumn(array $values)
Add the "updated at" column to an array of values.
at line 1469
protected array
addUniqueIdsToUpsertValues(array $values)
Add unique IDs to the inserted values.
at line 1489
protected array
addTimestampsToUpsertValues(array $values)
Add timestamps to the inserted values.
at line 1514
protected array
addUpdatedAtToUpsertColumns(array $update)
Add the "updated at" column to the updated columns.
at line 1541
mixed
delete()
Delete records from the database.
at line 1555
mixed
forceDelete()
Run the default delete function on the builder.
Since we do not apply scopes here, the row will actually be deleted.
at line 1563
void
onDelete(Closure $callback)
Register a replacement for the default delete function.
at line 1571
bool
hasNamedScope(string $scope)
Determine if the given model has a scope.
at line 1579
mixed
scopes(array|string $scopes)
Call the given local model scopes.
at line 1606
Builder
applyScopes()
Apply the scopes to the Eloquent builder instance and return it.
at line 1651
Builder
applyScopeCallback(callable $scope)
Apply a scope callback to the query.
Keep existing and callback-added WHERE constraints logically separate so conditions in either group cannot change the meaning of the other, including when later constraints are added.
at line 1661
protected mixed
callScope(callable $scope, array $parameters = [])
Apply the given scope on the current builder instance.
at line 1684
protected mixed
callNamedScope(string $scope, array $parameters = [])
Apply the given named scope on the current builder instance.
at line 1694
protected void
addNewWheresWithinGroup(Builder $query, int $originalWhereCount)
Nest where conditions by slicing them at the given where count.
at line 1717
protected void
groupWhereSliceForScope(Builder $query, array $whereSlice)
Slice where conditions at the given offset and add them to the query as a nested condition.
at line 1734
protected array
createNestedWhere(array $whereSlice, string $boolean = 'and')
Create a where array with nested where conditions.
at line 1750
Builder
with(array|string $relations, Closure|string|null $callback = null)
Specify relationships that should be eager loaded.
at line 1768
Builder
without(mixed $relations)
Prevent the specified relations from being eager loaded.
at line 1783
Builder
withOnly(array|string $relations)
Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
at line 1795
Model
newModelInstance(array $attributes = [])
Create a new instance of the model being queried.
at line 1807
protected array
parseWithRelations(array $relations)
Parse a list of relations into individuals.
at line 1830
protected array
prepareNestedWithRelationships(array $relations, string $prefix = '')
Prepare nested with relationships.
at line 1878
protected Closure
combineConstraints(array $constraints)
Combine an array of constraints into a single constraint.
at line 1892
protected array
parseNameAndAttributeSelectionConstraint(string $name)
Parse the attribute select constraints from the name.
at line 1903
protected array
createSelectWithConstraint(string $name)
Create a constraint to select the given columns for the relation.
at line 1919
protected array
addNestedWiths(string $name, array $results)
Parse the nested relationships in a relation.
at line 1945
Builder
withAttributes(Expression|array|string $attributes, mixed $value = null, bool $asConditions = true)
Specify attributes that should be added to any new models created by this builder.
The given key / value pairs will also be added as where conditions to the query.
at line 1967
Builder
withCasts(array $casts)
Apply query-time casts to the model instance.
at line 1982
mixed
withSavepointIfNeeded(Closure $scope)
Execute the given Closure within a transaction savepoint if needed.
at line 1992
protected Collection
getUnionBuilders()
Get the Eloquent builder instances that are used in the union of the query.
at line 2002
Builder
getQuery()
Get the underlying query builder instance.
at line 2022
Builder
toBase()
Get a base query builder instance.
at line 2030
array
getEagerLoads()
Get the relationships being eagerly loaded.
at line 2040
Builder
setEagerLoads(array $eagerLoad)
Set the relationships being eagerly loaded.
at line 2052
Builder
withoutEagerLoad(array $relations)
Indicate that the given relationships should not be eagerly loaded.
at line 2064
Builder
withoutEagerLoads()
Flush the relationships being eagerly loaded.
at line 2072
int|null
getLimit()
Get the "limit" value from the query or null if it's not set.
at line 2080
int|null
getOffset()
Get the "offset" value from the query or null if it's not set.
at line 2088
protected string
defaultKeyName()
Get the default key name of the table.
at line 2098
Model
getModel()
Get the model instance being queried.
at line 2108
Builder
newQuery()
Get a fresh query builder with the model's default scopes and eager loads.
at line 2134
string
qualifyColumn(Expression|string $column)
Qualify the given column name by the model's table.
at line 2154
array
qualifyColumns(array $columns)
Qualify the given columns with the model's table.
at line 2168
protected string|null
getTableAlias()
Get the alias or table name that qualifies the query's source columns.
at line 2176
Closure|null
getMacro(string $name)
Get the given macro by name.
at line 2184
bool
hasMacro(string $name)
Checks if a macro is registered.
at line 2192
static Closure|null
getGlobalMacro(string $name)
Get the given global macro by name.
at line 2200
static bool
hasGlobalMacro(string $name)
Checks if a global macro is registered.
at line 2208
static void
flushState()
Flush all static state.
at line 2218
mixed
__get(string $key)
Dynamically access builder proxies.
at line 2234
mixed
__call(string $method, array $parameters)
Dynamically handle calls into the query instance.
at line 2276
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls into the query instance.
at line 2308
static protected void
registerMixin(object $mixin, bool $replace)
Register the given mixin with the builder.
at line 2324
Builder
clone()
Clone the Eloquent query builder.
at line 2332
Builder
cloneWithout(array $properties)
Clone the Eloquent query builder without the given query properties.
at line 2344
Builder
cloneWithoutBindings(array $except)
Clone the Eloquent query builder without the given query bindings.
at line 2366
void
__clone()
Force a clone of the underlying query builder when cloning.
at line 59
$this
whereCan(UnitEnum|string $ability, mixed $user = 'null')
No description
at line 59
$this
withCan(UnitEnum|string> $abilities, mixed $user = 'null')
No description
at line 59
$this
fetchUsing(mixed ...$fetchUsing)
No description
at line 59
$this
useWritePdo()
No description