QueryBuilder
class QueryBuilder extends Builder
Traits
Properties
| protected Builder | $query | The base query builder instance. |
from Builder |
| protected TModel | $model | The model being queried. |
from Builder |
| array | $pendingAttributes | The attributes that should be added to new models created by this builder. |
from Builder |
| protected array | $eagerLoad | The relationships that should be eager loaded. |
from Builder |
| static protected array | $macros | All of the globally registered builder macros. |
from Builder |
| protected array | $localMacros | All of the locally registered builder macros. |
from Builder |
| protected Closure|null | $onDelete | A replacement for the typical delete function. |
from Builder |
| protected list<string> | $propertyPassthru | The properties that should be returned from query builder. |
from Builder |
| protected list<string> | $passthru | The methods that should be returned from query builder. |
from Builder |
| protected array | $scopes | Applied global scopes. |
from Builder |
| protected array | $removedScopes | Removed global scopes. |
from Builder |
| protected Closure> | $afterQueryCallbacks | The callbacks that should be invoked after retrieving data from the database. |
from Builder |
| protected Closure> | $onCloneCallbacks | The callbacks that should be invoked on clone. |
from Builder |
| $this|HigherOrderBuilderProxy read-only | $orWhere | from Builder | |
| $this|HigherOrderBuilderProxy read-only | $whereNot | from Builder | |
| $this|HigherOrderBuilderProxy read-only | $orWhereNot | from Builder |
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.
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 original column name of the given column, without any aliasing.
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.
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.
Remove all or passed registered global scopes.
Remove all global scopes except the given scopes.
Add a basic where clause to the query.
Add a basic where clause to the query, and return the first result.
Add an "or where" clause to the query.
Add a basic "where not" clause to the query.
Add an "or where not" clause to the query.
Add an "order by" clause for a timestamp to the query.
Add an "order by" clause for a timestamp to the query.
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 sole model by its primary key.
Find multiple models by their primary keys.
Find a model by its primary key or throw an exception.
Find a model by its primary key or return fresh model instance.
Find a model by its primary key or call a callback.
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.
Create or update a record matching the attributes, and fill it with values.
Create a record matching the attributes, or increment the existing record.
Execute the query and get the first result or call a callback.
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 hydrated models without eager loading.
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.
Add a generic "order by" clause if the query doesn't already have one.
Get a collection with the values of a given column.
Paginate the given query.
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.
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 timestamps to the inserted values.
Add the "updated at" column to the updated columns.
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.
Specify relationships that should be eager loaded.
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.
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.
Indicate that the given relationships should not be eagerly loaded.
Dynamically handle calls into the query instance.
Dynamically handle calls into the query instance.
Register the given mixin with the builder.
Get node's lft and rgt values.
Get plain node data.
Scope limits query to select just root node.
Limit results to ancestors of specified node.
No description
No description
Get ancestors of specified node.
No description
Add node selection statement between specified range.
Add node selection statement between specified range joined with or operator.
Add constraint statement to descendants of specified node.
No description
No description
No description
No description
Get descendants of specified node.
No description
No description
Constraint nodes to those that are after specified node.
Constraint nodes to those that are before specified node.
No description
No description
Include depth level into the result.
Get wrapped lft and rgt column names.
Get a wrapped table name.
Wrap model's key name.
Exclude root node from the result.
Equivalent of withoutRoot.
Get only nodes that have children.
Order by node position.
Order by reversed node position.
Move a node to the new position.
Make or remove gap in the tree. Negative height will remove gap.
Get patch for columns.
Get patch for single column.
Get statistics of errors of the tree.
No description
No description
No description
No description
Get the number of total errors of the tree.
Get whether the tree is broken.
No description
Rebuild the tree based on raw data.
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 39
bool
chunk(int $count, callable $callback)
Chunk the results of the query.
in
BuildsQueries at line 90
Collection
chunkMap(callable $callback, int $count = 1000)
Run a map over each item while chunking.
in
BuildsQueries at line 108
bool
each(callable $callback, int $count = 1000)
Execute a callback over each item while chunking.
in
BuildsQueries at line 124
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 134
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 144
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 212
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 228
LazyCollection
lazy(int $chunkSize = 1000)
Query lazily, by chunks of the given size.
in
BuildsQueries at line 258
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 268
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 278
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 321
null|TValue
first(array|string $columns = ['*'])
Execute the query and get the first result.
in
BuildsQueries at line 334
TValue
firstOrFail(array|string $columns = ['*'], string|null $message = null)
Execute the query and get the first result or throw an exception.
in
BuildsQueries at line 351
TValue
sole(array|string $columns = ['*'])
Execute the query and get the first result if it's the sole matching record.
in
BuildsQueries at line 374
protected CursorPaginator
paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)
Paginate the given query using a cursor paginator.
in
BuildsQueries at line 469
protected string
getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)
Get the original column name of the given column, without any aliasing.
in
BuildsQueries at line 491
protected LengthAwarePaginator
paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
Create a new length-aware paginator instance.
in
BuildsQueries at line 505
protected Paginator
simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)
Create a new simple paginator instance.
in
BuildsQueries at line 518
protected CursorPaginator
cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)
Create a new cursor paginator instance.
in
BuildsQueries at line 534
BuildsQueries
tap(callable $callback)
Pass the query to a given callback and then return it.
in
BuildsQueries at line 549
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 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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".
in
QueriesRelationships at line 140
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 150
QueriesRelationships
orDoesntHave(Relation|string $relation)
Add a relationship count / exists condition to the query with an "or".
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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".
in
QueriesRelationships at line 202
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 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".
in
QueriesRelationships 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.
in
QueriesRelationships at line 290
protected BelongsTo
getBelongsToRelation(MorphTo $relation, string $type)
Get the BelongsTo relationship for a single polymorphic type.
in
QueriesRelationships 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".
in
QueriesRelationships 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.
in
QueriesRelationships at line 337
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 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.
in
QueriesRelationships 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".
in
QueriesRelationships 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.
in
QueriesRelationships 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".
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships at line 559
QueriesRelationships
whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a morph-to relationship condition to the query.
in
QueriesRelationships at line 605
QueriesRelationships
whereNotMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')
Add a not morph-to relationship condition to the query.
in
QueriesRelationships at line 649
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 660
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 672
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 714
QueriesRelationships
orWhereBelongsTo(mixed $related, string|null $relationshipName = null)
Add a "BelongsTo" relationship with an "or where" clause to the query.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships 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.
in
QueriesRelationships at line 873
protected string
getRelationHashedColumn(string $column, Relation $relation)
Get the relation hashed column name for the given column and relation.
in
QueriesRelationships at line 887
QueriesRelationships
withCount(mixed $relations)
Add subselect queries to count the relations.
in
QueriesRelationships at line 895
QueriesRelationships
withMax(string|array $relation, Expression|string $column)
Add subselect queries to include the max of the relation's column.
in
QueriesRelationships at line 903
QueriesRelationships
withMin(string|array $relation, Expression|string $column)
Add subselect queries to include the min of the relation's column.
in
QueriesRelationships at line 911
QueriesRelationships
withSum(string|array $relation, Expression|string $column)
Add subselect queries to include the sum of the relation's column.
in
QueriesRelationships at line 919
QueriesRelationships
withAvg(string|array $relation, Expression|string $column)
Add subselect queries to include the average of the relation's column.
in
QueriesRelationships at line 927
QueriesRelationships
withExists(string|array $relation)
Add subselect queries to include the existence of related models.
in
QueriesRelationships 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.
in
QueriesRelationships at line 952
QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
in
QueriesRelationships at line 979
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 993
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 1010
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
in
QueriesRelationships at line 1020
protected bool
canUseExistsForExistenceCheck(string $operator, Expression|int $count)
Check if we can run an "exists" query to optimize performance.
in
Builder at line 174
Model
make(array $attributes = [])
Create and return an un-saved model instance.
in
Builder at line 182
Builder
withGlobalScope(string $identifier, Closure|Scope $scope)
Register a new global scope.
in
Builder at line 196
Builder
withoutGlobalScope(Scope|string $scope)
Remove a registered global scope.
in
Builder at line 212
Builder
withoutGlobalScopes(array|null $scopes = null)
Remove all or passed registered global scopes.
in
Builder at line 228
Builder
withoutGlobalScopesExcept(array $scopes = [])
Remove all global scopes except the given scopes.
in
Builder at line 240
array
removedScopes()
Get an array of global scopes that were removed from the query.
in
Builder at line 248
Builder
whereKey(mixed $id)
Add a where clause on the primary key to the query.
in
Builder at line 274
Builder
whereKeyNot(mixed $id)
Add a where clause on the primary key to the query.
in
Builder at line 300
Builder
except(mixed $models)
Exclude the given models from the query results.
in
Builder at line 314
Builder
where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
in
Builder at line 339
Model|null
firstWhere(array|Closure|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.
in
Builder at line 349
Builder
orWhere(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null)
Add an "or where" clause to the query.
in
Builder at line 365
Builder
whereNot(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic "where not" clause to the query.
in
Builder at line 375
Builder
orWhereNot(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null)
Add an "or where not" clause to the query.
in
Builder at line 383
Builder
latest(Expression|string|null $column = null)
Add an "order by" clause for a timestamp to the query.
in
Builder at line 397
Builder
oldest(Expression|string|null $column = null)
Add an "order by" clause for a timestamp to the query.
in
Builder at line 413
Collection
hydrate(array $items)
Create a collection of models from plain arrays.
in
Builder at line 433
bool
fillAndInsert(array $values)
Insert into the database after merging the model's default attributes, setting timestamps, and casting values.
in
Builder at line 443
int
fillAndInsertOrIgnore(array $values)
Insert (ignoring errors) into the database after merging the model's default attributes, setting timestamps, and casting values.
in
Builder at line 453
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.
in
Builder at line 464
array
fillForInsert(array $values)
Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values.
in
Builder at line 491
Collection
fromQuery(string $query, array $bindings = [])
Create a collection of models from a raw query.
in
Builder at line 503
Model|Collection|null
find(mixed $id, array|string $columns = ['*'])
Find a model by its primary key.
in
Builder at line 520
Model
findSole(mixed $id, array|string $columns = ['*'])
Find a sole model by its primary key.
in
Builder at line 530
Collection
findMany(Arrayable|array $ids, array|string $columns = ['*'])
Find multiple models by their primary keys.
in
Builder at line 548
Model|Collection
findOrFail(mixed $id, array|string $columns = ['*'])
Find a model by its primary key or throw an exception.
in
Builder at line 580
Model|Collection
findOrNew(mixed $id, array|string $columns = ['*'])
Find a model by its primary key or return fresh model instance.
in
Builder at line 602
mixed
findOr(mixed $id, Closure|array|string $columns = ['*'], Closure|null $callback = null)
Find a model by its primary key or call a callback.
in
Builder at line 622
Model
firstOrNew(array $attributes = [], Closure|array $values = [])
Get the first record matching the attributes or instantiate it.
in
Builder at line 636
Model
firstOrCreate(array $attributes = [], Closure|array $values = [])
Get the first record matching the attributes. If the record is not found, create it.
in
Builder at line 650
Model
createOrFirst(array $attributes = [], Closure|array $values = [])
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
in
Builder at line 665
Model
updateOrCreate(array $attributes, Closure|array $values = [])
Create or update a record matching the attributes, and fill it with values.
in
Builder at line 679
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.
in
Builder at line 713
mixed
firstOr(Closure|array $columns = ['*'], Closure|null $callback = null)
Execute the query and get the first result or call a callback.
in
Builder at line 748
mixed
value(Expression|string $column)
Get a single column's value from the first result of a query.
in
Builder at line 765
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.
in
Builder at line 777
mixed
valueOrFail(Expression|string $column)
Get a single column's value from the first result of the query or throw an exception.
in
Builder at line 789
Collection
get(array|string $columns = ['*'])
Execute the query as a "select" statement.
in
Builder at line 810
array
getModels(array|string $columns = ['*'])
Get the hydrated models without eager loading.
in
Builder at line 823
array
eagerLoadRelations(array $models)
Eager load the relationships for the models.
in
Builder at line 840
protected array
eagerLoadRelation(array $models, string $name, Closure $constraints)
Eagerly load the relationship on a set of models.
in
Builder at line 866
Relation
getRelation(string $name)
Get the relation instance for the given relation name.
in
Builder at line 894
protected array
relationsNestedUnder(string $relation)
Get the deeply nested relations for a given top-level relation.
in
Builder at line 913
protected bool
isNestedUnder(string $relation, string $name)
Determine if the relationship is nested.
in
Builder at line 921
Builder
afterQuery(Closure $callback)
Register a closure to be invoked after the query is executed.
in
Builder at line 931
Collection
applyAfterQueryCallbacks(Collection $result)
Invoke the "after query" modification callbacks.
in
Builder at line 945
LazyCollection
cursor()
Get a lazy collection for the given query.
in
Builder at line 957
protected void
enforceOrderBy()
Add a generic "order by" clause if the query doesn't already have one.
in
Builder at line 969
Collection
pluck(Expression|string $column, string|null $key = null)
Get a collection with the values of a given column.
in
Builder at line 998
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.
in
Builder at line 1019
Paginator
simplePaginate(int|null $perPage = null, array|string $columns = ['*'], string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
in
Builder at line 1039
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.
in
Builder at line 1049
protected Collection
ensureOrderForCursorPagination(bool $shouldReverse = false)
Ensure the proper order by required for cursor pagination.
in
Builder at line 1082
Model
create(array $attributes = [])
Save a new model and return the instance.
in
Builder at line 1094
Model
createQuietly(array $attributes = [])
Save a new model and return the instance without raising model events.
in
Builder at line 1104
Model
forceCreate(array $attributes)
Save a new model and return the instance. Allow mass-assignment.
in
Builder at line 1116
Model
forceCreateQuietly(array $attributes = [])
Save a new model instance with mass assignment without raising model events.
in
Builder at line 1124
int
update(array $values)
Update records in the database.
in
Builder at line 1132
int
upsert(array $values, array|string $uniqueBy, array|null $update = null)
Insert new records or update the existing ones.
in
Builder at line 1156
false|int
touch(array|string|null $column = null)
Update the column's update timestamp.
in
Builder at line 1180
int
increment(Expression|string $column, mixed $amount = 1, array $extra = [])
Increment a column's value by a given amount.
in
Builder at line 1192
int
decrement(Expression|string $column, mixed $amount = 1, array $extra = [])
Decrement a column's value by a given amount.
in
Builder at line 1207
int
incrementEach(array $columns, array $extra = [])
Increment the given column's values by the given amounts.
in
Builder at line 1221
int
decrementEach(array $columns, array $extra = [])
Decrement the given column's values by the given amounts.
in
Builder at line 1232
protected array
addUpdatedAtColumn(array $values)
Add the "updated at" column to an array of values.
in
Builder at line 1271
protected array
addUniqueIdsToUpsertValues(array $values)
Add unique IDs to the inserted values.
in
Builder at line 1291
protected array
addTimestampsToUpsertValues(array $values)
Add timestamps to the inserted values.
in
Builder at line 1316
protected array
addUpdatedAtToUpsertColumns(array $update)
Add the "updated at" column to the updated columns.
in
Builder at line 1336
mixed
delete()
Delete records from the database.
in
Builder at line 1350
mixed
forceDelete()
Run the default delete function on the builder.
Since we do not apply scopes here, the row will actually be deleted.
in
Builder at line 1358
void
onDelete(Closure $callback)
Register a replacement for the default delete function.
in
Builder at line 1366
bool
hasNamedScope(string $scope)
Determine if the given model has a scope.
in
Builder at line 1374
mixed
scopes(array|string $scopes)
Call the given local model scopes.
in
Builder at line 1401
Builder
applyScopes()
Apply the scopes to the Eloquent builder instance and return it.
in
Builder at line 1437
protected mixed
callScope(callable $scope, array $parameters = [])
Apply the given scope on the current builder instance.
in
Builder at line 1460
protected mixed
callNamedScope(string $scope, array $parameters = [])
Apply the given named scope on the current builder instance.
in
Builder at line 1470
protected void
addNewWheresWithinGroup(Builder $query, int $originalWhereCount)
Nest where conditions by slicing them at the given where count.
in
Builder at line 1493
protected void
groupWhereSliceForScope(Builder $query, array $whereSlice)
Slice where conditions at the given offset and add them to the query as a nested condition.
in
Builder at line 1515
protected array
createNestedWhere(array $whereSlice, string $boolean = 'and')
Create a where array with nested where conditions.
in
Builder at line 1530
Builder
with(array|string $relations, Closure|string|null $callback = null)
Specify relationships that should be eager loaded.
in
Builder at line 1546
Builder
without(mixed $relations)
Prevent the specified relations from being eager loaded.
in
Builder at line 1560
Builder
withOnly(array|string $relations)
Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
in
Builder at line 1572
Model
newModelInstance(array $attributes = [])
Create a new instance of the model being queried.
in
Builder at line 1584
protected array
parseWithRelations(array $relations)
Parse a list of relations into individuals.
in
Builder at line 1607
protected array
prepareNestedWithRelationships(array $relations, string $prefix = '')
Prepare nested with relationships.
in
Builder at line 1655
protected Closure
combineConstraints(array $constraints)
Combine an array of constraints into a single constraint.
in
Builder at line 1669
protected array
parseNameAndAttributeSelectionConstraint(string $name)
Parse the attribute select constraints from the name.
in
Builder at line 1680
protected array
createSelectWithConstraint(string $name)
Create a constraint to select the given columns for the relation.
in
Builder at line 1694
protected array
addNestedWiths(string $name, array $results)
Parse the nested relationships in a relation.
in
Builder at line 1718
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.
in
Builder at line 1738
Builder
withCasts(array $casts)
Apply query-time casts to the model instance.
in
Builder at line 1753
mixed
withSavepointIfNeeded(Closure $scope)
Execute the given Closure within a transaction savepoint if needed.
in
Builder at line 1763
protected Collection
getUnionBuilders()
Get the Eloquent builder instances that are used in the union of the query.
in
Builder at line 1799
array
getEagerLoads()
Get the relationships being eagerly loaded.
in
Builder at line 1807
Builder
setEagerLoads(array $eagerLoad)
Set the relationships being eagerly loaded.
in
Builder at line 1817
Builder
withoutEagerLoad(array $relations)
Indicate that the given relationships should not be eagerly loaded.
in
Builder at line 1835
int|null
getLimit()
Get the "limit" value from the query or null if it's not set.
in
Builder at line 1843
int|null
getOffset()
Get the "offset" value from the query or null if it's not set.
in
Builder at line 1851
protected string
defaultKeyName()
Get the default key name of the table.
in
Builder at line 1874
Builder
setModel(Model $model)
Set a model instance for the model being queried.
in
Builder at line 1887
string
qualifyColumn(Expression|string $column)
Qualify the given column name by the model's table.
in
Builder at line 1897
array
qualifyColumns(Expression|array $columns)
Qualify the given columns with the model's table.
in
Builder at line 1913
bool
hasMacro(string $name)
Checks if a macro is registered.
in
Builder at line 1921
static Closure|null
getGlobalMacro(string $name)
Get the given global macro by name.
in
Builder at line 1929
static bool
hasGlobalMacro(string $name)
Checks if a global macro is registered.
in
Builder at line 1937
static void
flushState()
Flush all static state.
in
Builder at line 1947
mixed
__get(string $key)
Dynamically access builder proxies.
in
Builder at line 1963
mixed
__call(string $method, array $parameters)
Dynamically handle calls into the query instance.
in
Builder at line 2005
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls into the query instance.
in
Builder at line 2037
static protected void
registerMixin(object $mixin, bool $replace)
Register the given mixin with the builder.
in
Builder at line 2061
Builder
onClone(Closure $callback)
Register a closure to be invoked on a clone.
in
Builder at line 2071
void
__clone()
Force a clone of the underlying query builder when cloning.
at line 22
array
getNodeData(mixed $id, bool $required = false)
Get node's lft and rgt values.
at line 41
array
getPlainNodeData(mixed $id, bool $required = false)
Get plain node data.
at line 49
QueryBuilder
whereIsRoot()
Scope limits query to select just root node.
at line 60
QueryBuilder
whereAncestorOf(mixed $id, bool $andSelf = false, string $boolean = 'and')
Limit results to ancestors of specified node.
at line 105
QueryBuilder
orWhereAncestorOf(mixed $id, bool $andSelf = false)
No description
at line 110
QueryBuilder
whereAncestorOrSelf(mixed $id)
No description
at line 118
Collection
ancestorsOf(mixed $id, array $columns = ['*'])
Get ancestors of specified node.
at line 124
Collection
ancestorsAndSelf(mixed $id, array $columns = ['*'])
No description
at line 133
QueryBuilder
whereNodeBetween(array $values, string $boolean = 'and', bool $not = false, Builder|null $query = null)
Add node selection statement between specified range.
at line 144
QueryBuilder
orWhereNodeBetween(array $values)
Add node selection statement between specified range joined with or operator.
at line 152
QueryBuilder
whereDescendantOf(mixed $id, string $boolean = 'and', bool $not = false, bool $andSelf = false)
Add constraint statement to descendants of specified node.
at line 177
QueryBuilder
whereNotDescendantOf(mixed $id)
No description
at line 182
QueryBuilder
orWhereDescendantOf(mixed $id)
No description
at line 187
QueryBuilder
orWhereNotDescendantOf(mixed $id)
No description
at line 192
QueryBuilder
whereDescendantOrSelf(mixed $id, string $boolean = 'and', bool $not = false)
No description
at line 200
Collection
descendantsOf(mixed $id, array $columns = ['*'], bool $andSelf = false)
Get descendants of specified node.
at line 209
Collection
descendantsAndSelf(mixed $id, array $columns = ['*'])
No description
at line 214
protected QueryBuilder
whereIsBeforeOrAfter(mixed $id, string $operator, string $boolean)
No description
at line 243
QueryBuilder
whereIsAfter(mixed $id, string $boolean = 'and')
Constraint nodes to those that are after specified node.
at line 251
QueryBuilder
whereIsBefore(mixed $id, string $boolean = 'and')
Constraint nodes to those that are before specified node.
at line 256
Builder|QueryBuilder
whereIsLeaf()
No description
at line 263
Collection
leaves(array $columns = ['*'])
No description
at line 271
QueryBuilder
withDepth(string $as = 'depth')
Include depth level into the result.
at line 299
protected array
wrappedColumns()
Get wrapped lft and rgt column names.
at line 312
protected string
wrappedTable()
Get a wrapped table name.
at line 320
protected string
wrappedKey()
Wrap model's key name.
at line 328
QueryBuilder
withoutRoot()
Exclude root node from the result.
at line 339
QueryBuilder
hasParent()
Equivalent of withoutRoot.
at line 350
QueryBuilder
hasChildren()
Get only nodes that have children.
at line 362
QueryBuilder
defaultOrder(string $dir = 'asc')
Order by node position.
at line 375
QueryBuilder
reversed()
Order by reversed node position.
at line 383
int
moveNode(mixed $key, int $position)
Move a node to the new position.
at line 429
int
makeGap(int $cut, int $height)
Make or remove gap in the tree. Negative height will remove gap.
at line 444
protected array
patch(array $params)
Get patch for columns.
at line 461
protected Expression
columnPatch(string $col, array $params)
Get patch for single column.
at line 494
array
countErrors()
Get statistics of errors of the tree.
at line 521
protected Builder
getOdnessQuery()
No description
at line 534
protected Builder
getDuplicatesQuery()
No description
at line 563
protected Builder
getWrongParentQuery()
No description
at line 604
protected Builder
getMissingParentQuery()
No description
at line 638
int
getTotalErrors()
Get the number of total errors of the tree.
at line 646
bool
isBroken()
Get whether the tree is broken.
at line 655
int
fixTree(Model|null $root = null)
Fixes the tree based on parentage info.
Nodes with invalid parent are saved as roots.
at line 677
int
fixSubtree(Model $root)
No description
at line 682
protected int
fixNodes(array $dictionary, Model|null $parent = null)
No description
at line 717
static protected int
reorderNodes(array $dictionary, array $updated, mixed $parentId = null, int $cut = 1)
No description
at line 750
int
rebuildTree(array $data, bool $delete = false, int|Model|null $root = null)
Rebuild the tree based on raw data.
If item data does not contain primary key, new node will be created.
at line 798
int
rebuildSubtree(mixed $root, array $data, bool $delete = false)
No description
at line 803
protected void
buildRebuildDictionary(array $dictionary, array $data, array $existing, mixed $parentId = null)
No description
at line 848
QueryBuilder
applyNestedSetScope(string|null $table = null)
No description
at line 857
Model|null
root(array $columns = ['*'])
Get the root node.