class QueryBuilder extends Builder

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.

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

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.

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.

bool
chunk(int $count, callable $callback)

Chunk the results of the query.

chunkMap(callable $callback, int $count = 1000)

Run a map over each item while chunking.

bool
each(callable $callback, int $count = 1000)

Execute a callback over each item while chunking.

bool
chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null)

Chunk the results of a query by comparing IDs.

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.

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.

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.

lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)

Query lazily, by chunking the results of a query by comparing IDs.

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.

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.

mixed
getLastIdFromChunk(mixed $result, string $alias)

Get the ID of the last result of a chunk to continue paging from.

mixed
getNextPageIdFromChunk(mixed $result, string $column, string $alias)

Prepare the last chunk ID for comparison with the paging column.

string
getPagingAttribute(Model $model, string $column)

Get the model attribute behind a qualified paging column.

null|TValue
first(array|string $columns = ['*'])

Execute the query and get the first result.

TValue
firstOrFail(array|string $columns = ['*'], string|null $message = null)

Execute the query and get the first result or throw an exception.

TValue
sole(array|string $columns = ['*'])

Execute the query and get the first result if it's the sole matching record.

paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)

Paginate the given query using a cursor paginator.

getBuilderForCursorPage()

Get the builder that owns cursor binding and page execution.

mixed
getCursorParameterBinding(Cursor $cursor, string $parameter)

Get a cursor parameter for database binding.

string
getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)

Get the original column name of the given column, without any aliasing.

bool
isCursorExpression(Builder $query, string $parameter, string $original)

Determine whether the resolved cursor column is a declared SQL expression.

paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)

Create a new length-aware paginator instance.

simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)

Create a new simple paginator instance.

cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)

Create a new cursor paginator instance.

tap(callable $callback)

Pass the query to a given callback and then return it.

TReturn is null|TReturn)
pipe(callable $callback)

Pass the query to a given callback and return the result.

mixed
forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

mixed
forwardDecoratedCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object, returning $this if the forwarded call returned itself.

static never
throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

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.

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.

orHas(Relation|string $relation, string $operator = '>=', Expression|int $count = 1)

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

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

Add a relationship count / exists condition to the query.

orDoesntHave(Relation|string $relation)

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

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.

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.

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

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

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

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

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

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.

getBelongsToRelation(MorphTo $relation, string $type)

Get the BelongsTo relationship for a single polymorphic type.

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

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

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

orDoesntHaveMorph(MorphTo|string $relation, string|array $types)

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

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.

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

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

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

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

whereRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add a basic where clause to a relationship query.

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.

orWhereRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add an "or where" clause to a relationship query.

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.

orWhereDoesntHaveRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add an "or where" clause to a relationship query.

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.

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.

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.

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.

whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')

Add a morph-to relationship condition to the query.

whereNotMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')

Add a not morph-to relationship condition to the query.

orWhereMorphedTo(MorphTo|string $relation, mixed $model)

Add a morph-to relationship condition to the query with an "or where" clause.

orWhereNotMorphedTo(MorphTo|string $relation, mixed $model)

Add a not morph-to relationship condition to the query with an "or where" clause.

string
getMorphTypeForQuery(string $model)

Resolve the morph type for a relationship query.

whereBelongsTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')

Add a "belongs to" relationship where clause to the query.

orWhereBelongsTo(mixed $related, string|null $relationshipName = null)

Add a "BelongsTo" relationship with an "or where" clause to the query.

whereAttachedTo(mixed $related, string|null $relationshipName = null, string $boolean = 'and')

Add a "belongs to many" relationship where clause to the query.

orWhereAttachedTo(mixed $related, string|null $relationshipName = null)

Add a "belongs to many" relationship with an "or where" clause to the query.

withAggregate(mixed $relations, Expression|string $column, string|null $function = null)

Add subselect queries to include an aggregate value for a relationship.

string
getRelationHashedColumn(string $column, Relation $relation)

Get the relation hashed column name for the given column and relation.

withCount(mixed $relations)

Add subselect queries to count the relations.

withMax(string|array $relation, Expression|string $column)

Add subselect queries to include the max of the relation's column.

withMin(string|array $relation, Expression|string $column)

Add subselect queries to include the min of the relation's column.

withSum(string|array $relation, Expression|string $column)

Add subselect queries to include the sum of the relation's column.

withAvg(string|array $relation, Expression|string $column)

Add subselect queries to include the average of the relation's column.

withExists(string|array $relation)

Add subselect queries to include the existence of related models.

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

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

mergeConstraintsFrom(Builder $from)

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

array
requalifyWhereTables(array $wheres, string $from, string $to)

Updates the table name for any columns with a new qualified name.

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

Add a sub-query count clause to this query.

void
ensureNoTimeoutOnRelationshipConstraint(Builder $query)

Ensure a relationship constraint does not carry a statement-level timeout.

getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

bool
canUseExistsForExistenceCheck(string $operator, Expression|int $count)

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

__construct(Builder $query)

Create a new Eloquent query builder instance.

from  Builder
make(array $attributes = [])

Create and return an un-saved model instance.

from  Builder
withGlobalScope(int|string $identifier, Closure|Scope $scope)

Register a new global scope.

from  Builder
withoutGlobalScope(Scope|int|string $scope)

Remove a registered global scope.

from  Builder
withoutGlobalScopes(array|null $scopes = null)

Remove all or passed registered global scopes.

from  Builder
withoutGlobalScopesExcept(array $scopes = [])

Remove all global scopes except the given scopes.

from  Builder
array
removedScopes()

Get an array of global scopes that were removed from the query.

from  Builder
whereKey(mixed $id, string $boolean = 'and', bool $not = false)

Add a where clause on the primary key to the query.

from  Builder
whereKeyNot(mixed $id, string $boolean = 'and')

Add a where clause on the primary key to the query.

from  Builder
orWhereKey(mixed $id)

Add an "or where" clause on the primary key to the query.

from  Builder
orWhereKeyNot(mixed $id)

Add an "or where not" clause on the primary key to the query.

from  Builder
except(mixed $models)

Exclude the given models from the query results.

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

from  Builder
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.

from  Builder
orWhere(array|Closure|Builder|Builder|Relation|Expression|string $column, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query.

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

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

from  Builder
latest(Closure|Builder|Builder|Relation|Expression|string|null $column = null)

Add an "order by" clause for a timestamp to the query.

from  Builder
oldest(Closure|Builder|Builder|Relation|Expression|string|null $column = null)

Add an "order by" clause for a timestamp to the query.

from  Builder
hydrate(array $items)

Create a collection of models from plain arrays.

from  Builder
bool
fillAndInsert(array $values)

Insert into the database after merging the model's default attributes, setting timestamps, and casting values.

from  Builder
int
fillAndInsertOrIgnore(array $values)

Insert (ignoring errors) into the database after merging the model's default attributes, setting timestamps, and casting values.

from  Builder
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.

from  Builder
array
fillForInsert(array $values)

Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values.

from  Builder
fromQuery(string $query, array $bindings = [])

Create a collection of models from a raw query.

from  Builder
find(mixed $id, array|string $columns = ['*'])

Find a model by its primary key.

from  Builder
findSole(mixed $id, array|string $columns = ['*'])

Find a sole model by its primary key.

from  Builder
findMany(Arrayable|array $ids, array|string $columns = ['*'])

Find multiple models by their primary keys.

from  Builder
findOrFail(mixed $id, array|string $columns = ['*'])

Find a model by its primary key or throw an exception.

from  Builder
findOrNew(mixed $id, array|string $columns = ['*'])

Find a model by its primary key or return fresh model instance.

from  Builder
mixed
findOr(mixed $id, Closure|array|string $columns = ['*'], Closure|null $callback = null)

Find a model by its primary key or call a callback.

from  Builder
firstOrNew(array $attributes = [], Closure|array $values = [])

Get the first record matching the attributes or instantiate it.

from  Builder
firstOrCreate(array $attributes = [], Closure|array $values = [])

Get the first record matching the attributes. If the record is not found, create it.

from  Builder
createOrFirst(array $attributes = [], Closure|array $values = [])

Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.

from  Builder
void
ensureCanCreateOrFirst()

Validate first-or-create and create-or-first operations, including relationship calls.

from  Builder
updateOrCreate(array $attributes, Closure|array $values = [])

Create or update a record matching the attributes, and fill it with values.

from  Builder
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.

from  Builder
mixed
firstOr(Closure|array $columns = ['*'], Closure|null $callback = null)

Execute the query and get the first result or call a callback.

from  Builder
mixed
value(Expression|string $column)

Get a single column's value from the first result of a query.

from  Builder
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.

from  Builder
mixed
valueOrFail(Expression|string $column)

Get a single column's value from the first result of the query or throw an exception.

from  Builder
mixed
getValueFromModel(Model $model, Expression|string $column)

Get the selected value through the model's attribute accessors.

from  Builder
get(array|string $columns = ['*'])

Execute the query as a "select" statement.

from  Builder
array
getModels(array|string $columns = ['*'])

Get the hydrated models without eager loading.

from  Builder
array
eagerLoadRelations(array $models)

Eager load the relationships for the models.

from  Builder
array
eagerLoadRelation(array $models, string $name, Closure $constraints)

Eagerly load the relationship on a set of models.

from  Builder
getRelation(string $name)

Get the relation instance for the given relation name.

from  Builder
array
relationsNestedUnder(string $relation)

Get the deeply nested relations for a given top-level relation.

from  Builder
bool
isNestedUnder(string $relation, string $name)

Determine if the relationship is nested.

from  Builder
afterQuery(Closure $callback)

Register a closure to be invoked after the query is executed.

from  Builder
applyAfterQueryCallbacks(Collection $result)

Invoke the "after query" modification callbacks.

from  Builder
cursor()

Get a lazy collection for the given query.

from  Builder
void
enforceOrderBy()

Add a generic "order by" clause if the query doesn't already have one.

from  Builder
pluck(Expression|string $column, string|null $key = null)

Get a collection with the values of a given column.

from  Builder
array
modelKeys()

Get an array of primary keys from the query result.

from  Builder
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.

from  Builder
simplePaginate(int|null $perPage = null, array|string $columns = ['*'], string $pageName = 'page', int|null $page = null)

Paginate the given query into a simple paginator.

from  Builder
cursorPaginate(int|null $perPage = null, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)

Paginate the given query into a cursor paginator.

from  Builder
ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

from  Builder
create(array $attributes = [])

Save a new model and return the instance.

from  Builder
createQuietly(array $attributes = [])

Save a new model and return the instance without raising model events.

from  Builder
forceCreate(array $attributes)

Save a new model and return the instance. Allow mass-assignment.

from  Builder
forceCreateQuietly(array $attributes = [])

Save a new model instance with mass assignment without raising model events.

from  Builder
int
update(array $values)

Update records in the database.

from  Builder
int
updateFrom(array $values)

Update records in a PostgreSQL database using the update from syntax.

from  Builder
int
upsert(array $values, array|string $uniqueBy, array|null $update = null)

Insert new records or update the existing ones.

from  Builder
false|int
touch(array|string|null $column = null)

Update the column's update timestamp.

from  Builder
int
increment(Expression|string $column, mixed $amount = 1, array $extra = [])

Increment a column's value by a given amount.

from  Builder
int
decrement(Expression|string $column, mixed $amount = 1, array $extra = [])

Decrement a column's value by a given amount.

from  Builder
int
incrementEach(array $columns, array $extra = [])

Increment the given column's values by the given amounts.

from  Builder
int
decrementEach(array $columns, array $extra = [])

Decrement the given column's values by the given amounts.

from  Builder
array
addUpdatedAtColumn(array $values)

Add the "updated at" column to an array of values.

from  Builder
array
addUniqueIdsToUpsertValues(array $values)

Add unique IDs to the inserted values.

from  Builder
array
addTimestampsToUpsertValues(array $values)

Add timestamps to the inserted values.

from  Builder
array
addUpdatedAtToUpsertColumns(array $update)

Add the "updated at" column to the updated columns.

from  Builder
mixed
delete()

Delete records from the database.

from  Builder
mixed
forceDelete()

Run the default delete function on the builder.

from  Builder
void
onDelete(Closure $callback)

Register a replacement for the default delete function.

from  Builder
bool
hasNamedScope(string $scope)

Determine if the given model has a scope.

from  Builder
mixed
scopes(array|string $scopes)

Call the given local model scopes.

from  Builder
applyScopes()

Apply the scopes to the Eloquent builder instance and return it.

from  Builder
applyScopeCallback(callable $scope)

Apply a scope callback to the query.

from  Builder
mixed
callScope(callable $scope, array $parameters = [])

Apply the given scope on the current builder instance.

from  Builder
mixed
callNamedScope(string $scope, array $parameters = [])

Apply the given named scope on the current builder instance.

from  Builder
void
addNewWheresWithinGroup(Builder $query, int $originalWhereCount)

Nest where conditions by slicing them at the given where count.

from  Builder
void
groupWhereSliceForScope(Builder $query, array $whereSlice)

Slice where conditions at the given offset and add them to the query as a nested condition.

from  Builder
array
createNestedWhere(array $whereSlice, string $boolean = 'and')

Create a where array with nested where conditions.

from  Builder
with(array|string $relations, Closure|string|null $callback = null)

Specify relationships that should be eager loaded.

from  Builder
without(mixed $relations)

Prevent the specified relations from being eager loaded.

from  Builder
withOnly(array|string $relations)

Set the relationships that should be eager loaded while removing any previously added eager loading specifications.

from  Builder
newModelInstance(array $attributes = [])

Create a new instance of the model being queried.

from  Builder
array
parseWithRelations(array $relations)

Parse a list of relations into individuals.

from  Builder
array
prepareNestedWithRelationships(array $relations, string $prefix = '')

Prepare nested with relationships.

from  Builder
combineConstraints(array $constraints)

Combine an array of constraints into a single constraint.

from  Builder
array
parseNameAndAttributeSelectionConstraint(string $name)

Parse the attribute select constraints from the name.

from  Builder
array
createSelectWithConstraint(string $name)

Create a constraint to select the given columns for the relation.

from  Builder
array
addNestedWiths(string $name, array $results)

Parse the nested relationships in a relation.

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

from  Builder
withCasts(array $casts)

Apply query-time casts to the model instance.

from  Builder
mixed
withSavepointIfNeeded(Closure $scope)

Execute the given Closure within a transaction savepoint if needed.

from  Builder
getUnionBuilders()

Get the Eloquent builder instances that are used in the union of the query.

from  Builder
getQuery()

Get the underlying query builder instance.

from  Builder
setQuery(Builder $query)

Set the underlying query builder instance.

from  Builder
toBase()

Get a base query builder instance.

from  Builder
array
getEagerLoads()

Get the relationships being eagerly loaded.

from  Builder
setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

from  Builder
withoutEagerLoad(array $relations)

Indicate that the given relationships should not be eagerly loaded.

from  Builder
withoutEagerLoads()

Flush the relationships being eagerly loaded.

from  Builder
int|null
getLimit()

Get the "limit" value from the query or null if it's not set.

from  Builder
int|null
getOffset()

Get the "offset" value from the query or null if it's not set.

from  Builder
string
defaultKeyName()

Get the default key name of the table.

from  Builder
getModel()

Get the model instance being queried.

from  Builder
newQuery()

Get a fresh query builder with the model's default scopes and eager loads.

from  Builder
setModel(Model $model)

Set a model instance for the model being queried.

from  Builder
string
qualifyColumn(Expression|string $column)

Qualify the given column name by the model's table.

from  Builder
array
qualifyColumns(array $columns)

Qualify the given columns with the model's table.

from  Builder
string|null
getTableAlias()

Get the alias or table name that qualifies the query's source columns.

from  Builder
Closure|null
getMacro(string $name)

Get the given macro by name.

from  Builder
bool
hasMacro(string $name)

Checks if a macro is registered.

from  Builder
static Closure|null
getGlobalMacro(string $name)

Get the given global macro by name.

from  Builder
static bool
hasGlobalMacro(string $name)

Checks if a global macro is registered.

from  Builder
static void
flushState()

Flush all static state.

from  Builder
mixed
__get(string $key)

Dynamically access builder proxies.

from  Builder
mixed
__call(string $method, array $parameters)

Dynamically handle calls into the query instance.

from  Builder
static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls into the query instance.

from  Builder
static void
registerMixin(object $mixin, bool $replace)

Register the given mixin with the builder.

from  Builder
clone()

Clone the Eloquent query builder.

from  Builder
cloneWithout(array $properties)

Clone the Eloquent query builder without the given query properties.

from  Builder
cloneWithoutBindings(array $except)

Clone the Eloquent query builder without the given query bindings.

from  Builder
onClone(Closure $callback)

Register a closure to be invoked on a clone.

from  Builder
void
__clone()

Force a clone of the underlying query builder when cloning.

from  Builder
$this
whereCan(UnitEnum|string $ability, mixed $user = 'null')

No description

from  Builder
$this
withCan(UnitEnum|string> $abilities, mixed $user = 'null')

No description

from  Builder
$this
fetchUsing(mixed ...$fetchUsing)

No description

from  Builder
$this
useWritePdo()

No description

from  Builder
array
getNodeData(int|string $id, bool $required = false)

Get a node's structural values.

array
getPlainNodeData(int|string $id, bool $required = false)

Get plain node data.

whereIsRoot()

Scope limits query to select just root node.

whereAncestorOf(Model|int|string $id, bool $andSelf = false, string $boolean = 'and')

Limit results to ancestors of specified node.

orWhereAncestorOf(Model|int|string $id, bool $andSelf = false)

Add an or constraint for ancestors of a node.

whereAncestorOrSelf(Model|int|string $id)

Limit results to ancestors and the node itself.

ancestorsOf(Model|int|string $id, array $columns = ['*'])

Get ancestors of specified node.

ancestorsAndSelf(Model|int|string $id, array $columns = ['*'])

Get ancestors and the node itself.

whereNodeBetween(array $values, string $boolean = 'and', bool $not = false, Builder|null $query = null)

Add node selection statement between specified range.

orWhereNodeBetween(array $values)

Add node selection statement between specified range joined with or operator.

whereDescendantOf(Model|int|string $id, string $boolean = 'and', bool $not = false, bool $andSelf = false)

Add constraint statement to descendants of specified node.

whereNotDescendantOf(Model|int|string $id)

Exclude descendants of a node.

orWhereDescendantOf(Model|int|string $id)

Add an or constraint for descendants of a node.

orWhereNotDescendantOf(Model|int|string $id)

Add an or exclusion for descendants of a node.

whereDescendantOrSelf(Model|int|string $id, string $boolean = 'and', bool $not = false)

Limit results to descendants and the node itself.

descendantsOf(Model|int|string $id, array $columns = ['*'], bool $andSelf = false)

Get descendants of specified node.

descendantsAndSelf(Model|int|string $id, array $columns = ['*'])

Get descendants and the node itself.

whereIsBeforeOrAfter(Model|int|string $id, string $operator, string $boolean)

Add a positional constraint relative to a node.

whereIsAfter(Model|int|string $id, string $boolean = 'and')

Constraint nodes to those that are after specified node.

whereIsBefore(Model|int|string $id, string $boolean = 'and')

Constraint nodes to those that are before specified node.

whereIsLeaf()

Limit results to leaf nodes.

leaves(array $columns = ['*'])

Get the leaf nodes.

withDepth(string $as = 'depth')

Include depth level into the result.

array
wrappedColumns()

Get wrapped lft and rgt column names.

withoutRoot()

Exclude root node from the result.

hasParent()

Equivalent of withoutRoot.

hasChildren()

Get only nodes that have children.

defaultOrder(string $dir = 'asc')

Order by node position.

reversed()

Order by reversed node position.

int
moveNode(int|string $key, int $position, int|null $targetDepth = null, array $nodeData = [])

Move a node to the new position.

int
depthForPosition(int $position)

Get the depth of a node inserted at the given position.

newNestedSetLookupQuery(string|null $table = null)

Create a nested set lookup that inherits the current read route.

newLookupBaseQuery()

Create a base query for wrapping lookups that inherits the current read route.

int
makeGap(int $cut, int $height)

Make or remove gap in the tree. Negative height will remove gap.

array
patch(array $params)

Get patch for columns.

depthPatch(string $column, array $params)

Get the depth-column patch for a moved subtree.

columnPatch(string $col, array $params)

Get patch for single column.

array
countErrors()

Get statistics of errors of the tree.

getInvalidIntervalsQuery(bool $count = true)

Get the invalid interval query.

getEndpointEventsQuery()

Get the ordered endpoint events query.

getDuplicateEndpointGroupsQuery()

Get duplicate endpoint groups.

getDuplicateEndpointsQuery()

Get the duplicate endpoint count query.

getMissingEndpointsQuery()

Get the missing endpoint range query.

getEndpointStateQuery()

Get expected and active endpoint depths.

getCrossingIntervalsQuery()

Get the crossing interval count query.

getMissingParentQuery(bool $count = true)

Get the missing parent query.

getWrongParentQuery(bool $count = true)

Get the wrong parent query.

getWrongDepthQuery(bool $count = true)

Get the wrong depth query.

void
addScopeColumnComparisons(Builder $query, string $firstAlias, string $secondAlias)

Add null-safe scope comparisons between aliases.

void
ensureConcreteNestedSetScope(string $operation = 'diagnostics')

Ensure every nested set scope attribute is selected.

void
ensureUsableNodeForPositionalQuery(Model $node)

Ensure that a node can supply coordinates to this query.

void
prepareRepairRoot(Model $root, string $operation)

Prepare one authoritative root for subtree repair or rebuild.

void
ensureSubtreeBoundsAreValid(Model $root)

Ensure a subtree has valid bounds containing every parent-linked node.

int
getTotalErrors()

Get the number of total errors of the tree.

bool
isBroken()

Get whether the tree is broken.

int
fixTree(Model|null $root = null, array $extraColumns = [])

Fix the tree based on parentage information.

int
fixSubtree(Model|null $root, array $extraColumns = [])

Fix a subtree based on parentage information.

int
fixNodes(array $roots, array $childrenByParent, array $parentOrder, Model|null $parent = null)

Repair ordered nodes from their parent dictionaries.

bool
applyRepairPlacement(Model $model, array $placement, int|null $gapCut, int $height)

Apply a repair placement and save the node when its stored values differ.

bool
repairRowMatches(Model $model, stdClass $row, array $placement)

Determine whether a row already stores a repair placement.

static array
shiftRepairBoundsAfterGap(array $attributes, string $lftName, string $rgtName, int $cut, int $height)

Shift stored bounds as the preceding gap update shifted the row.

static int
reorderNodes(array $childrenByParent, array $placements, array $nodes, string $keyName, int|string|null $parentId, int $cut, int $depth)

Place a set of nodes at contiguous bounds and depths, recording each placement in tree order.

static void
assignRepairNode(Model $model, int $lft, int $rgt, int|string|null $parentId, int|null $depth)

Assign structural values to a model owned by repair or rebuild.

static void
addRepairNode(array $roots, array $childrenByParent, array $parentOrder, Model|stdClass $node, int|string|null $parentId)

Add a repair node to its parent bucket.

static void
saveRepairNode(Model $model)

Save a node changed during repair.

int
rebuildTree(array $data, bool $delete = false, Model|null $root = null)

Rebuild the tree based on raw data.

int
rebuildSubtree(Model $root, array $data, bool $delete = false)

Rebuild a subtree from raw data.

void
buildRebuildDictionary(array $roots, array $childrenByParent, array $parentOrder, array $data, array $existing, array $scopeAttributes, int|string|null $parentId = null)

Build repair dictionaries from nested rebuild data.

applyNestedSetScope(string|null $table = null)

Apply the concrete tree scope.

Model|null
root(array $columns = ['*'])

Get the root node.

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in BuildsQueries at line 45
bool chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

in BuildsQueries at line 101
Collection chunkMap(callable $callback, int $count = 1000)

Run a map over each item while chunking.

Parameters

callable $callback
int $count

Return Value

Collection

in BuildsQueries at line 119
bool each(callable $callback, int $count = 1000)

Execute a callback over each item while chunking.

Parameters

callable $callback
int $count

Return Value

bool

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.

Parameters

int $count
callable $callback
string|null $column
string|null $alias

Return Value

bool

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.

Parameters

int $count
callable $callback
string|null $column
string|null $alias

Return Value

bool

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.

Parameters

int $count
callable $callback
string|null $column
string|null $alias
SortDirection|bool $descending

Return Value

bool

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.

Parameters

callable $callback
int $count
string|null $column
string|null $alias

Return Value

bool

in BuildsQueries at line 248
LazyCollection lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

Parameters

int $chunkSize

Return Value

LazyCollection

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.

Parameters

int $chunkSize
string|null $column
string|null $alias

Return Value

LazyCollection

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.

Parameters

int $chunkSize
string|null $column
string|null $alias

Return Value

LazyCollection

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.

Parameters

int $chunkSize
string|null $column
string|null $alias
SortDirection|bool $descending

Return Value

LazyCollection

Exceptions

InvalidArgumentException
RuntimeException

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.

Parameters

mixed $result
string $alias

Return Value

mixed

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.

Parameters

mixed $result
string $column
string $alias

Return Value

mixed

in BuildsQueries at line 425
protected string getPagingAttribute(Model $model, string $column)

Get the model attribute behind a qualified paging column.

Parameters

Model $model
string $column

Return Value

string

in BuildsQueries at line 447
null|TValue first(array|string $columns = ['*'])

Execute the query and get the first result.

Parameters

array|string $columns

Return Value

null|TValue

in BuildsQueries at line 459
TValue firstOrFail(array|string $columns = ['*'], string|null $message = null)

Execute the query and get the first result or throw an exception.

Parameters

array|string $columns
string|null $message

Return Value

TValue

Exceptions

RecordNotFoundException

in BuildsQueries at line 479
TValue sole(array|string $columns = ['*'])

Execute the query and get the first result if it's the sole matching record.

Parameters

array|string $columns

Return Value

TValue

Exceptions

RecordsNotFoundException
MultipleRecordsFoundException

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.

Parameters

int $perPage
array|string $columns
string $cursorName
Cursor|string|null $cursor

Return Value

CursorPaginator

in BuildsQueries at line 561
protected BuildsQueries getBuilderForCursorPage()

Get the builder that owns cursor binding and page execution.

Return Value

BuildsQueries

in BuildsQueries at line 569
protected mixed getCursorParameterBinding(Cursor $cursor, string $parameter)

Get a cursor parameter for database binding.

Parameters

Cursor $cursor
string $parameter

Return Value

mixed

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.

Parameters

Builder|Builder $builder
string $parameter

Return Value

string

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.

Parameters

Builder $query
string $parameter
string $original

Return Value

bool

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.

Parameters

Collection $items
int $total
int $perPage
int $currentPage
array $options

Return Value

LengthAwarePaginator

in BuildsQueries at line 639
protected Paginator simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)

Create a new simple paginator instance.

Parameters

Collection $items
int $perPage
int $currentPage
array $options

Return Value

Paginator

in BuildsQueries at line 649
protected CursorPaginator cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)

Create a new cursor paginator instance.

Parameters

Collection $items
int $perPage
Cursor|null $cursor
array $options

Return Value

CursorPaginator

in BuildsQueries at line 662
BuildsQueries tap(callable $callback)

Pass the query to a given callback and then return it.

Parameters

callable $callback

Return Value

BuildsQueries

in BuildsQueries at line 677
TReturn is null|TReturn) pipe(callable $callback)

Pass the query to a given callback and return the result.

Parameters

callable $callback

Return Value

TReturn is null|TReturn)

in ForwardsCalls at line 22
protected mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

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.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 66
static protected never throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

never

Exceptions

BadMethodCallException

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.

Parameters

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

Return Value

QueriesRelationships

Exceptions

RuntimeException

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.

Parameters

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

Return Value

QueriesRelationships

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

Parameters

Relation|string $relation
string $operator
Expression|int $count

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
string $boolean
Closure|null $callback

Return Value

QueriesRelationships

in QueriesRelationships at line 145
QueriesRelationships orDoesntHave(Relation|string $relation)

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

Parameters

Relation|string $relation

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|null $callback
string $operator
Expression|int $count

Return Value

QueriesRelationships

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.

Parameters

string $relation
Closure|null $callback
string $operator
Expression|int $count

Return Value

QueriesRelationships

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

Parameters

Relation|string $relation
Closure|null $callback
string $operator
Expression|int $count

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|null $callback

Return Value

QueriesRelationships

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

Parameters

Relation|string $relation
Closure|null $callback

Return Value

QueriesRelationships

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.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 311
protected BelongsTo getBelongsToRelation(MorphTo $relation, string $type)

Get the BelongsTo relationship for a single polymorphic type.

Parameters

MorphTo $relation
string $type

Return Value

BelongsTo

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

Parameters

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

Return Value

QueriesRelationships

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.

Parameters

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

Return Value

QueriesRelationships

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

Parameters

MorphTo|string $relation
string|array $types

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|null $callback
string $operator
Expression|int $count

Return Value

QueriesRelationships

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

Parameters

MorphTo|string $relation
string|array $types
Closure|null $callback
string $operator
Expression|int $count

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|null $callback

Return Value

QueriesRelationships

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

Parameters

MorphTo|string $relation
string|array $types
Closure|null $callback

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

string $relation
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

Relation|string $relation
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
string|array $types
Closure|string|array|Expression $column
mixed $operator
mixed $value

Return Value

QueriesRelationships

in QueriesRelationships at line 601
QueriesRelationships whereMorphedTo(MorphTo|string $relation, mixed $model, string $boolean = 'and')

Add a morph-to relationship condition to the query.

Parameters

MorphTo|string $relation
mixed $model
string $boolean

Return Value

QueriesRelationships

Exceptions

ClassMorphViolationException
InvalidArgumentException

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.

Parameters

MorphTo|string $relation
mixed $model
string $boolean

Return Value

QueriesRelationships

Exceptions

ClassMorphViolationException
InvalidArgumentException

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.

Parameters

MorphTo|string $relation
mixed $model

Return Value

QueriesRelationships

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.

Parameters

MorphTo|string $relation
mixed $model

Return Value

QueriesRelationships

in QueriesRelationships at line 722
protected string getMorphTypeForQuery(string $model)

Resolve the morph type for a relationship query.

Parameters

string $model

Return Value

string

Exceptions

ClassMorphViolationException

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.

Parameters

mixed $related
string|null $relationshipName
string $boolean

Return Value

QueriesRelationships

Exceptions

InvalidArgumentException
RelationNotFoundException

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.

Parameters

mixed $related
string|null $relationshipName

Return Value

QueriesRelationships

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.

Parameters

mixed $related
string|null $relationshipName
string $boolean

Return Value

QueriesRelationships

Exceptions

InvalidArgumentException
RelationNotFoundException

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.

Parameters

mixed $related
string|null $relationshipName

Return Value

QueriesRelationships

Exceptions

RuntimeException

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.

Parameters

mixed $relations
Expression|string $column
string|null $function

Return Value

QueriesRelationships

in QueriesRelationships at line 958
protected string getRelationHashedColumn(string $column, Relation $relation)

Get the relation hashed column name for the given column and relation.

Parameters

string $column
Relation $relation

Return Value

string

in QueriesRelationships at line 974
QueriesRelationships withCount(mixed $relations)

Add subselect queries to count the relations.

Parameters

mixed $relations

Return Value

QueriesRelationships

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.

Parameters

string|array $relation
Expression|string $column

Return Value

QueriesRelationships

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.

Parameters

string|array $relation
Expression|string $column

Return Value

QueriesRelationships

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.

Parameters

string|array $relation
Expression|string $column

Return Value

QueriesRelationships

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.

Parameters

string|array $relation
Expression|string $column

Return Value

QueriesRelationships

in QueriesRelationships at line 1024
QueriesRelationships withExists(string|array $relation)

Add subselect queries to include the existence of related models.

Parameters

string|array $relation

Return Value

QueriesRelationships

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.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 1054
QueriesRelationships mergeConstraintsFrom(Builder $from)

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

Parameters

Builder $from

Return Value

QueriesRelationships

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.

Parameters

array $wheres
string $from
string $to

Return Value

array

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.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 1112
protected void ensureNoTimeoutOnRelationshipConstraint(Builder $query)

Ensure a relationship constraint does not carry a statement-level timeout.

Parameters

Builder $query

Return Value

void

Exceptions

InvalidArgumentException

in QueriesRelationships at line 1126
protected Relation getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

Parameters

string $relation

Return Value

Relation

in QueriesRelationships at line 1136
protected bool canUseExistsForExistenceCheck(string $operator, Expression|int $count)

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

Parameters

string $operator
Expression|int $count

Return Value

bool

in Builder at line 184
__construct(Builder $query)

Create a new Eloquent query builder instance.

Parameters

Builder $query

in Builder at line 194
Model make(array $attributes = [])

Create and return an un-saved model instance.

Parameters

array $attributes

Return Value

Model

in Builder at line 204
Builder withGlobalScope(int|string $identifier, Closure|Scope $scope)

Register a new global scope.

Parameters

int|string $identifier
Closure|Scope $scope

Return Value

Builder

in Builder at line 220
Builder withoutGlobalScope(Scope|int|string $scope)

Remove a registered global scope.

Parameters

Scope|int|string $scope

Return Value

Builder

in Builder at line 238
Builder withoutGlobalScopes(array|null $scopes = null)

Remove all or passed registered global scopes.

Parameters

array|null $scopes

Return Value

Builder

in Builder at line 256
Builder withoutGlobalScopesExcept(array $scopes = [])

Remove all global scopes except the given scopes.

Parameters

array $scopes

Return Value

Builder

in Builder at line 268
array removedScopes()

Get an array of global scopes that were removed from the query.

Return Value

array

in Builder at line 278
Builder whereKey(mixed $id, string $boolean = 'and', bool $not = false)

Add a where clause on the primary key to the query.

Parameters

mixed $id
string $boolean
bool $not

Return Value

Builder

in Builder at line 312
Builder whereKeyNot(mixed $id, string $boolean = 'and')

Add a where clause on the primary key to the query.

Parameters

mixed $id
string $boolean

Return Value

Builder

in Builder at line 322
Builder orWhereKey(mixed $id)

Add an "or where" clause on the primary key to the query.

Parameters

mixed $id

Return Value

Builder

in Builder at line 332
Builder orWhereKeyNot(mixed $id)

Add an "or where not" clause on the primary key to the query.

Parameters

mixed $id

Return Value

Builder

in Builder at line 340
Builder except(mixed $models)

Exclude the given models from the query results.

Parameters

mixed $models

Return Value

Builder

in Builder 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.

Parameters

array|Closure|Builder|Builder|Relation|Expression|string $column
mixed $operator
mixed $value
string $boolean

Return Value

Builder

in Builder 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.

Parameters

array|Closure|Builder|Builder|Relation|Expression|string $column
mixed $operator
mixed $value
string $boolean

Return Value

Model|null

in Builder 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.

Parameters

array|Closure|Builder|Builder|Relation|Expression|string $column
mixed $operator
mixed $value

Return Value

Builder

in Builder 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.

Parameters

array|Closure|Builder|Builder|Relation|Expression|string $column
mixed $operator
mixed $value
string $boolean

Return Value

Builder

in Builder 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.

Parameters

array|Closure|Builder|Builder|Relation|Expression|string $column
mixed $operator
mixed $value

Return Value

Builder

in Builder 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.

Parameters

Closure|Builder|Builder|Relation|Expression|string|null $column

Return Value

Builder

in Builder 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.

Parameters

Closure|Builder|Builder|Relation|Expression|string|null $column

Return Value

Builder

in Builder at line 478
Collection hydrate(array $items)

Create a collection of models from plain arrays.

Parameters

array $items

Return Value

Collection

in Builder at line 498
bool fillAndInsert(array $values)

Insert into the database after merging the model's default attributes, setting timestamps, and casting values.

Parameters

array $values

Return Value

bool

in Builder 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.

Parameters

array $values

Return Value

int

in Builder 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.

Parameters

array $values

Return Value

int

in Builder at line 529
array fillForInsert(array $values)

Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values.

Parameters

array $values

Return Value

array

in Builder at line 556
Collection fromQuery(string $query, array $bindings = [])

Create a collection of models from a raw query.

Parameters

string $query
array $bindings

Return Value

Collection

in Builder at line 568
Model|Collection|null find(mixed $id, array|string $columns = ['*'])

Find a model by its primary key.

Parameters

mixed $id
array|string $columns

Return Value

Model|Collection|null

in Builder at line 585
Model findSole(mixed $id, array|string $columns = ['*'])

Find a sole model by its primary key.

Parameters

mixed $id
array|string $columns

Return Value

Model

Exceptions

TModel>
MultipleRecordsFoundException

in Builder at line 595
Collection findMany(Arrayable|array $ids, array|string $columns = ['*'])

Find multiple models by their primary keys.

Parameters

Arrayable|array $ids
array|string $columns

Return Value

Collection

in Builder at line 613
Model|Collection findOrFail(mixed $id, array|string $columns = ['*'])

Find a model by its primary key or throw an exception.

Parameters

mixed $id
array|string $columns

Return Value

Model|Collection

Exceptions

TModel>

in Builder at line 651
Model|Collection findOrNew(mixed $id, array|string $columns = ['*'])

Find a model by its primary key or return fresh model instance.

Parameters

mixed $id
array|string $columns

Return Value

Model|Collection

in Builder 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.

Parameters

mixed $id
Closure|array|string $columns
Closure|null $callback

Return Value

mixed

in Builder at line 710
Model firstOrNew(array $attributes = [], Closure|array $values = [])

Get the first record matching the attributes or instantiate it.

Parameters

array $attributes
Closure|array $values

Return Value

Model

in Builder 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.

Parameters

array $attributes
Closure|array $values

Return Value

Model

in Builder 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.

Parameters

array $attributes
Closure|array $values

Return Value

Model

Exceptions

UniqueConstraintViolationException

in Builder 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.

Return Value

void

in Builder at line 770
Model updateOrCreate(array $attributes, Closure|array $values = [])

Create or update a record matching the attributes, and fill it with values.

Parameters

array $attributes
Closure|array $values

Return Value

Model

in Builder 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.

Parameters

array $attributes
string $column
float|int $default
float|int $step
array $extra

Return Value

Model

in Builder at line 818
mixed firstOr(Closure|array $columns = ['*'], Closure|null $callback = null)

Execute the query and get the first result or call a callback.

Parameters

Closure|array $columns
Closure|null $callback

Return Value

mixed

in Builder at line 853
mixed value(Expression|string $column)

Get a single column's value from the first result of a query.

Parameters

Expression|string $column

Return Value

mixed

in Builder 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.

Parameters

Expression|string $column

Return Value

mixed

Exceptions

TModel>
MultipleRecordsFoundException

in Builder 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.

Parameters

Expression|string $column

Return Value

mixed

Exceptions

TModel>

in Builder at line 886
protected mixed getValueFromModel(Model $model, Expression|string $column)

Get the selected value through the model's attribute accessors.

Parameters

Model $model
Expression|string $column

Return Value

mixed

in Builder at line 902
Collection get(array|string $columns = ['*'])

Execute the query as a "select" statement.

Parameters

array|string $columns

Return Value

Collection

in Builder at line 923
array getModels(array|string $columns = ['*'])

Get the hydrated models without eager loading.

Parameters

array|string $columns

Return Value

array

in Builder at line 936
array eagerLoadRelations(array $models)

Eager load the relationships for the models.

Parameters

array $models

Return Value

array

in Builder at line 953
protected array eagerLoadRelation(array $models, string $name, Closure $constraints)

Eagerly load the relationship on a set of models.

Parameters

array $models
string $name
Closure $constraints

Return Value

array

in Builder at line 979
Relation getRelation(string $name)

Get the relation instance for the given relation name.

Parameters

string $name

Return Value

Relation

in Builder at line 1007
protected array relationsNestedUnder(string $relation)

Get the deeply nested relations for a given top-level relation.

Parameters

string $relation

Return Value

array

in Builder at line 1026
protected bool isNestedUnder(string $relation, string $name)

Determine if the relationship is nested.

Parameters

string $relation
string $name

Return Value

bool

in Builder at line 1036
Builder afterQuery(Closure $callback)

Register a closure to be invoked after the query is executed.

Parameters

Closure $callback

Return Value

Builder

in Builder 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.

Parameters

Collection $result

Return Value

Collection

in Builder at line 1067
LazyCollection cursor()

Get a lazy collection for the given query.

Return Value

LazyCollection

in Builder at line 1083
protected void enforceOrderBy()

Add a generic "order by" clause if the query doesn't already have one.

Return Value

void

in Builder at line 1099
Collection pluck(Expression|string $column, string|null $key = null)

Get a collection with the values of a given column.

Parameters

Expression|string $column
string|null $key

Return Value

Collection

in Builder at line 1135
array modelKeys()

Get an array of primary keys from the query result.

Return Value

array

in Builder 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.

Parameters

Closure|int|null $perPage
array|string $columns
string $pageName
int|null $page
Closure|int|null $total

Return Value

LengthAwarePaginator

Exceptions

InvalidArgumentException

in Builder 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.

Parameters

int|null $perPage
array|string $columns
string $pageName
int|null $page

Return Value

Paginator

in Builder 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.

Parameters

int|null $perPage
array|string $columns
string $cursorName
Cursor|string|null $cursor

Return Value

CursorPaginator

in Builder at line 1204
protected Collection ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

Parameters

bool $shouldReverse

Return Value

Collection

in Builder at line 1267
Model create(array $attributes = [])

Save a new model and return the instance.

Parameters

array $attributes

Return Value

Model

in Builder at line 1279
Model createQuietly(array $attributes = [])

Save a new model and return the instance without raising model events.

Parameters

array $attributes

Return Value

Model

in Builder at line 1289
Model forceCreate(array $attributes)

Save a new model and return the instance. Allow mass-assignment.

Parameters

array $attributes

Return Value

Model

in Builder at line 1301
Model forceCreateQuietly(array $attributes = [])

Save a new model instance with mass assignment without raising model events.

Parameters

array $attributes

Return Value

Model

in Builder at line 1309
int update(array $values)

Update records in the database.

Parameters

array $values

Return Value

int

in Builder at line 1317
int updateFrom(array $values)

Update records in a PostgreSQL database using the update from syntax.

Parameters

array $values

Return Value

int

in Builder at line 1325
int upsert(array $values, array|string $uniqueBy, array|null $update = null)

Insert new records or update the existing ones.

Parameters

array $values
array|string $uniqueBy
array|null $update

Return Value

int

in Builder at line 1349
false|int touch(array|string|null $column = null)

Update the column's update timestamp.

Parameters

array|string|null $column

Return Value

false|int

in Builder at line 1373
int increment(Expression|string $column, mixed $amount = 1, array $extra = [])

Increment a column's value by a given amount.

Parameters

Expression|string $column
mixed $amount
array $extra

Return Value

int

in Builder at line 1385
int decrement(Expression|string $column, mixed $amount = 1, array $extra = [])

Decrement a column's value by a given amount.

Parameters

Expression|string $column
mixed $amount
array $extra

Return Value

int

in Builder at line 1400
int incrementEach(array $columns, array $extra = [])

Increment the given column's values by the given amounts.

Parameters

array $columns
array $extra

Return Value

int

in Builder at line 1414
int decrementEach(array $columns, array $extra = [])

Decrement the given column's values by the given amounts.

Parameters

array $columns
array $extra

Return Value

int

in Builder at line 1425
protected array addUpdatedAtColumn(array $values)

Add the "updated at" column to an array of values.

Parameters

array $values

Return Value

array

in Builder at line 1469
protected array addUniqueIdsToUpsertValues(array $values)

Add unique IDs to the inserted values.

Parameters

array $values

Return Value

array

in Builder at line 1489
protected array addTimestampsToUpsertValues(array $values)

Add timestamps to the inserted values.

Parameters

array $values

Return Value

array

in Builder at line 1514
protected array addUpdatedAtToUpsertColumns(array $update)

Add the "updated at" column to the updated columns.

Parameters

array $update

Return Value

array

in Builder at line 1541
mixed delete()

Delete records from the database.

Return Value

mixed

in Builder 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.

Return Value

mixed

in Builder at line 1563
void onDelete(Closure $callback)

Register a replacement for the default delete function.

Parameters

Closure $callback

Return Value

void

in Builder at line 1571
bool hasNamedScope(string $scope)

Determine if the given model has a scope.

Parameters

string $scope

Return Value

bool

in Builder at line 1579
mixed scopes(array|string $scopes)

Call the given local model scopes.

Parameters

array|string $scopes

Return Value

mixed

in Builder at line 1606
Builder applyScopes()

Apply the scopes to the Eloquent builder instance and return it.

Return Value

Builder

in Builder 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.

Parameters

callable $scope

Return Value

Builder

in Builder at line 1661
protected mixed callScope(callable $scope, array $parameters = [])

Apply the given scope on the current builder instance.

Parameters

callable $scope
array $parameters

Return Value

mixed

in Builder at line 1684
protected mixed callNamedScope(string $scope, array $parameters = [])

Apply the given named scope on the current builder instance.

Parameters

string $scope
array $parameters

Return Value

mixed

in Builder at line 1694
protected void addNewWheresWithinGroup(Builder $query, int $originalWhereCount)

Nest where conditions by slicing them at the given where count.

Parameters

Builder $query
int $originalWhereCount

Return Value

void

in Builder 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.

Parameters

Builder $query
array $whereSlice

Return Value

void

in Builder at line 1734
protected array createNestedWhere(array $whereSlice, string $boolean = 'and')

Create a where array with nested where conditions.

Parameters

array $whereSlice
string $boolean

Return Value

array

in Builder at line 1750
Builder with(array|string $relations, Closure|string|null $callback = null)

Specify relationships that should be eager loaded.

Parameters

array|string $relations
Closure|string|null $callback

Return Value

Builder

in Builder at line 1768
Builder without(mixed $relations)

Prevent the specified relations from being eager loaded.

Parameters

mixed $relations

Return Value

Builder

in Builder at line 1783
Builder withOnly(array|string $relations)

Set the relationships that should be eager loaded while removing any previously added eager loading specifications.

Parameters

array|string $relations

Return Value

Builder

in Builder at line 1795
Model newModelInstance(array $attributes = [])

Create a new instance of the model being queried.

Parameters

array $attributes

Return Value

Model

in Builder at line 1807
protected array parseWithRelations(array $relations)

Parse a list of relations into individuals.

Parameters

array $relations

Return Value

array

in Builder at line 1830
protected array prepareNestedWithRelationships(array $relations, string $prefix = '')

Prepare nested with relationships.

Parameters

array $relations
string $prefix

Return Value

array

in Builder at line 1878
protected Closure combineConstraints(array $constraints)

Combine an array of constraints into a single constraint.

Parameters

array $constraints

Return Value

Closure

in Builder at line 1892
protected array parseNameAndAttributeSelectionConstraint(string $name)

Parse the attribute select constraints from the name.

Parameters

string $name

Return Value

array

in Builder at line 1903
protected array createSelectWithConstraint(string $name)

Create a constraint to select the given columns for the relation.

Parameters

string $name

Return Value

array

in Builder at line 1919
protected array addNestedWiths(string $name, array $results)

Parse the nested relationships in a relation.

Parameters

string $name
array $results

Return Value

array

in Builder 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.

Parameters

Expression|array|string $attributes
mixed $value
bool $asConditions

Return Value

Builder

in Builder at line 1967
Builder withCasts(array $casts)

Apply query-time casts to the model instance.

Parameters

array $casts

Return Value

Builder

in Builder at line 1982
mixed withSavepointIfNeeded(Closure $scope)

Execute the given Closure within a transaction savepoint if needed.

Parameters

Closure $scope

Return Value

mixed

in Builder at line 1992
protected Collection getUnionBuilders()

Get the Eloquent builder instances that are used in the union of the query.

Return Value

Collection

in Builder at line 2002
Builder getQuery()

Get the underlying query builder instance.

Return Value

Builder

in Builder at line 2012
Builder setQuery(Builder $query)

Set the underlying query builder instance.

Parameters

Builder $query

Return Value

Builder

in Builder at line 2022
Builder toBase()

Get a base query builder instance.

Return Value

Builder

in Builder at line 2030
array getEagerLoads()

Get the relationships being eagerly loaded.

Return Value

array

in Builder at line 2040
Builder setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

Parameters

array $eagerLoad

Return Value

Builder

in Builder at line 2052
Builder withoutEagerLoad(array $relations)

Indicate that the given relationships should not be eagerly loaded.

Parameters

array $relations

Return Value

Builder

in Builder at line 2064
Builder withoutEagerLoads()

Flush the relationships being eagerly loaded.

Return Value

Builder

in Builder at line 2072
int|null getLimit()

Get the "limit" value from the query or null if it's not set.

Return Value

int|null

in Builder at line 2080
int|null getOffset()

Get the "offset" value from the query or null if it's not set.

Return Value

int|null

in Builder at line 2088
protected string defaultKeyName()

Get the default key name of the table.

Return Value

string

in Builder at line 2098
Model getModel()

Get the model instance being queried.

Return Value

Model

in Builder at line 2108
Builder newQuery()

Get a fresh query builder with the model's default scopes and eager loads.

Return Value

Builder

in Builder at line 2121
Builder setModel(Model $model)

Set a model instance for the model being queried.

Parameters

Model $model

Return Value

Builder

in Builder at line 2134
string qualifyColumn(Expression|string $column)

Qualify the given column name by the model's table.

Parameters

Expression|string $column

Return Value

string

in Builder at line 2154
array qualifyColumns(array $columns)

Qualify the given columns with the model's table.

Parameters

array $columns

Return Value

array

in Builder at line 2168
protected string|null getTableAlias()

Get the alias or table name that qualifies the query's source columns.

Return Value

string|null

in Builder at line 2176
Closure|null getMacro(string $name)

Get the given macro by name.

Parameters

string $name

Return Value

Closure|null

in Builder at line 2184
bool hasMacro(string $name)

Checks if a macro is registered.

Parameters

string $name

Return Value

bool

in Builder at line 2192
static Closure|null getGlobalMacro(string $name)

Get the given global macro by name.

Parameters

string $name

Return Value

Closure|null

in Builder at line 2200
static bool hasGlobalMacro(string $name)

Checks if a global macro is registered.

Parameters

string $name

Return Value

bool

in Builder at line 2208
static void flushState()

Flush all static state.

Return Value

void

in Builder at line 2218
mixed __get(string $key)

Dynamically access builder proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

in Builder at line 2234
mixed __call(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

in Builder at line 2276
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Builder at line 2308
static protected void registerMixin(object $mixin, bool $replace)

Register the given mixin with the builder.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Builder at line 2324
Builder clone()

Clone the Eloquent query builder.

Return Value

Builder

in Builder at line 2332
Builder cloneWithout(array $properties)

Clone the Eloquent query builder without the given query properties.

Parameters

array $properties

Return Value

Builder

in Builder at line 2344
Builder cloneWithoutBindings(array $except)

Clone the Eloquent query builder without the given query bindings.

Parameters

array $except

Return Value

Builder

in Builder at line 2356
Builder onClone(Closure $callback)

Register a closure to be invoked on a clone.

Parameters

Closure $callback

Return Value

Builder

in Builder at line 2366
void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void

in Builder at line 59
$this whereCan(UnitEnum|string $ability, mixed $user = 'null')

No description

Parameters

UnitEnum|string $ability
mixed $user

Return Value

$this

in Builder at line 59
$this withCan(UnitEnum|string> $abilities, mixed $user = 'null')

No description

Parameters

UnitEnum|string> $abilities
mixed $user

Return Value

$this

in Builder at line 59
$this fetchUsing(mixed ...$fetchUsing)

No description

Parameters

mixed ...$fetchUsing

Return Value

$this

in Builder at line 59
$this useWritePdo()

No description

Return Value

$this

at line 29
array getNodeData(int|string $id, bool $required = false)

Get a node's structural values.

Parameters

int|string $id
bool $required

Return Value

array

at line 54
array getPlainNodeData(int|string $id, bool $required = false)

Get plain node data.

Parameters

int|string $id
bool $required

Return Value

array

at line 67
QueryBuilder whereIsRoot()

Scope limits query to select just root node.

Return Value

QueryBuilder

at line 77
QueryBuilder whereAncestorOf(Model|int|string $id, bool $andSelf = false, string $boolean = 'and')

Limit results to ancestors of specified node.

Parameters

Model|int|string $id
bool $andSelf
string $boolean

Return Value

QueryBuilder

at line 129
QueryBuilder orWhereAncestorOf(Model|int|string $id, bool $andSelf = false)

Add an or constraint for ancestors of a node.

Parameters

Model|int|string $id
bool $andSelf

Return Value

QueryBuilder

at line 137
QueryBuilder whereAncestorOrSelf(Model|int|string $id)

Limit results to ancestors and the node itself.

Parameters

Model|int|string $id

Return Value

QueryBuilder

at line 147
Collection ancestorsOf(Model|int|string $id, array $columns = ['*'])

Get ancestors of specified node.

Parameters

Model|int|string $id
array $columns

Return Value

Collection

at line 157
Collection ancestorsAndSelf(Model|int|string $id, array $columns = ['*'])

Get ancestors and the node itself.

Parameters

Model|int|string $id
array $columns

Return Value

Collection

at line 165
QueryBuilder whereNodeBetween(array $values, string $boolean = 'and', bool $not = false, Builder|null $query = null)

Add node selection statement between specified range.

Parameters

array $values
string $boolean
bool $not
Builder|null $query

Return Value

QueryBuilder

at line 180
QueryBuilder orWhereNodeBetween(array $values)

Add node selection statement between specified range joined with or operator.

Parameters

array $values

Return Value

QueryBuilder

at line 188
QueryBuilder whereDescendantOf(Model|int|string $id, string $boolean = 'and', bool $not = false, bool $andSelf = false)

Add constraint statement to descendants of specified node.

Parameters

Model|int|string $id
string $boolean
bool $not
bool $andSelf

Return Value

QueryBuilder

at line 215
QueryBuilder whereNotDescendantOf(Model|int|string $id)

Exclude descendants of a node.

Parameters

Model|int|string $id

Return Value

QueryBuilder

at line 223
QueryBuilder orWhereDescendantOf(Model|int|string $id)

Add an or constraint for descendants of a node.

Parameters

Model|int|string $id

Return Value

QueryBuilder

at line 231
QueryBuilder orWhereNotDescendantOf(Model|int|string $id)

Add an or exclusion for descendants of a node.

Parameters

Model|int|string $id

Return Value

QueryBuilder

at line 239
QueryBuilder whereDescendantOrSelf(Model|int|string $id, string $boolean = 'and', bool $not = false)

Limit results to descendants and the node itself.

Parameters

Model|int|string $id
string $boolean
bool $not

Return Value

QueryBuilder

at line 249
Collection descendantsOf(Model|int|string $id, array $columns = ['*'], bool $andSelf = false)

Get descendants of specified node.

Parameters

Model|int|string $id
array $columns
bool $andSelf

Return Value

Collection

at line 263
Collection descendantsAndSelf(Model|int|string $id, array $columns = ['*'])

Get descendants and the node itself.

Parameters

Model|int|string $id
array $columns

Return Value

Collection

at line 271
protected QueryBuilder whereIsBeforeOrAfter(Model|int|string $id, string $operator, string $boolean)

Add a positional constraint relative to a node.

Parameters

Model|int|string $id
string $operator
string $boolean

Return Value

QueryBuilder

at line 318
QueryBuilder whereIsAfter(Model|int|string $id, string $boolean = 'and')

Constraint nodes to those that are after specified node.

Parameters

Model|int|string $id
string $boolean

Return Value

QueryBuilder

at line 326
QueryBuilder whereIsBefore(Model|int|string $id, string $boolean = 'and')

Constraint nodes to those that are before specified node.

Parameters

Model|int|string $id
string $boolean

Return Value

QueryBuilder

at line 334
QueryBuilder whereIsLeaf()

Limit results to leaf nodes.

Return Value

QueryBuilder

at line 348
Collection leaves(array $columns = ['*'])

Get the leaf nodes.

Parameters

array $columns

Return Value

Collection

at line 356
QueryBuilder withDepth(string $as = 'depth')

Include depth level into the result.

Parameters

string $as

Return Value

QueryBuilder

at line 374
protected array wrappedColumns()

Get wrapped lft and rgt column names.

Return Value

array

at line 387
QueryBuilder withoutRoot()

Exclude root node from the result.

Return Value

QueryBuilder

at line 399
QueryBuilder hasParent()

Equivalent of withoutRoot.

Return Value

QueryBuilder

at line 411
QueryBuilder hasChildren()

Get only nodes that have children.

Return Value

QueryBuilder

at line 423
QueryBuilder defaultOrder(string $dir = 'asc')

Order by node position.

Parameters

string $dir

Return Value

QueryBuilder

at line 445
QueryBuilder reversed()

Order by reversed node position.

Return Value

QueryBuilder

at line 455
int moveNode(int|string $key, int $position, int|null $targetDepth = null, array $nodeData = [])

Move a node to the new position.

Parameters

int|string $key
int $position
int|null $targetDepth
array $nodeData

complete values keyed by the model's left, right, and depth column names

Return Value

int

at line 527
int depthForPosition(int $position)

Get the depth of a node inserted at the given position.

This replaces upstream's getDepth($position), which returns the enclosing node's depth.

Parameters

int $position

Return Value

int

at line 545
protected QueryBuilder newNestedSetLookupQuery(string|null $table = null)

Create a nested set lookup that inherits the current read route.

Parameters

string|null $table

Return Value

QueryBuilder

at line 555
protected Builder newLookupBaseQuery()

Create a base query for wrapping lookups that inherits the current read route.

Return Value

Builder

at line 565
int makeGap(int $cut, int $height)

Make or remove gap in the tree. Negative height will remove gap.

Parameters

int $cut
int $height

Return Value

int

at line 584
protected array patch(array $params)

Get patch for columns.

Parameters

array $params

Return Value

array

at line 610
protected Expression depthPatch(string $column, array $params)

Get the depth-column patch for a moved subtree.

Parameters

string $column
array $params

Return Value

Expression

at line 627
protected Expression columnPatch(string $col, array $params)

Get patch for single column.

Parameters

string $col
array $params

Return Value

Expression

at line 662
array countErrors()

Get statistics of errors of the tree.

Return Value

array

at line 691
protected Builder getInvalidIntervalsQuery(bool $count = true)

Get the invalid interval query.

Parameters

bool $count

Return Value

Builder

at line 710
protected Builder getEndpointEventsQuery()

Get the ordered endpoint events query.

Return Value

Builder

at line 731
protected Builder getDuplicateEndpointGroupsQuery()

Get duplicate endpoint groups.

Return Value

Builder

at line 743
protected Builder getDuplicateEndpointsQuery()

Get the duplicate endpoint count query.

Return Value

Builder

at line 753
protected Builder getMissingEndpointsQuery()

Get the missing endpoint range query.

Return Value

Builder

at line 776
protected Builder getEndpointStateQuery()

Get expected and active endpoint depths.

Return Value

Builder

at line 792
protected Builder getCrossingIntervalsQuery()

Get the crossing interval count query.

Return Value

Builder

at line 811
protected Builder getMissingParentQuery(bool $count = true)

Get the missing parent query.

Parameters

bool $count

Return Value

Builder

at line 842
protected Builder getWrongParentQuery(bool $count = true)

Get the wrong parent query.

Parameters

bool $count

Return Value

Builder

at line 898
protected Builder getWrongDepthQuery(bool $count = true)

Get the wrong depth query.

Parameters

bool $count

Return Value

Builder

at line 958
protected void addScopeColumnComparisons(Builder $query, string $firstAlias, string $secondAlias)

Add null-safe scope comparisons between aliases.

Parameters

Builder $query
string $firstAlias
string $secondAlias

Return Value

void

at line 980
protected void ensureConcreteNestedSetScope(string $operation = 'diagnostics')

Ensure every nested set scope attribute is selected.

Parameters

string $operation

Return Value

void

at line 999
protected void ensureUsableNodeForPositionalQuery(Model $node)

Ensure that a node can supply coordinates to this query.

Parameters

Model $node

Return Value

void

at line 1043
protected void prepareRepairRoot(Model $root, string $operation)

Prepare one authoritative root for subtree repair or rebuild.

Parameters

Model $root
string $operation

Return Value

void

at line 1091
protected void ensureSubtreeBoundsAreValid(Model $root)

Ensure a subtree has valid bounds containing every parent-linked node.

Parameters

Model $root

Return Value

void

at line 1133
int getTotalErrors()

Get the number of total errors of the tree.

Return Value

int

at line 1141
bool isBroken()

Get whether the tree is broken.

Return Value

bool

at line 1163
int fixTree(Model|null $root = null, array $extraColumns = [])

Fix the tree based on parentage information.

Nodes with invalid parents become roots of the repaired selection.

Parameters

Model|null $root
array $extraColumns

Return Value

int

at line 1210
int fixSubtree(Model|null $root, array $extraColumns = [])

Fix a subtree based on parentage information.

Parameters

Model|null $root
array $extraColumns

Return Value

int

at line 1218
protected int fixNodes(array $roots, array $childrenByParent, array $parentOrder, Model|null $parent = null)

Repair ordered nodes from their parent dictionaries.

Parameters

array $roots
array $childrenByParent
array $parentOrder
Model|null $parent

Return Value

int

at line 1317
protected bool applyRepairPlacement(Model $model, array $placement, int|null $gapCut, int $height)

Apply a repair placement and save the node when its stored values differ.

Returns whether the placement differs from the values stored before any subtree gap, so rows that only the gap update shifted are counted by that update instead.

Parameters

Model $model
array $placement
int|null $gapCut
int $height

Return Value

bool

at line 1366
protected bool repairRowMatches(Model $model, stdClass $row, array $placement)

Determine whether a row already stores a repair placement.

Parameters

Model $model
stdClass $row
array $placement

Return Value

bool

at line 1390
static protected array shiftRepairBoundsAfterGap(array $attributes, string $lftName, string $rgtName, int $cut, int $height)

Shift stored bounds as the preceding gap update shifted the row.

Parameters

array $attributes
string $lftName
string $rgtName
int $cut
int $height

Return Value

array

at line 1415
static protected int reorderNodes(array $childrenByParent, array $placements, array $nodes, string $keyName, int|string|null $parentId, int $cut, int $depth)

Place a set of nodes at contiguous bounds and depths, recording each placement in tree order.

Parameters

array $childrenByParent
array $placements
array $nodes
string $keyName
int|string|null $parentId
int $cut
int $depth

Return Value

int

at line 1483
static protected void assignRepairNode(Model $model, int $lft, int $rgt, int|string|null $parentId, int|null $depth)

Assign structural values to a model owned by repair or rebuild.

Parameters

Model $model
int $lft
int $rgt
int|string|null $parentId
int|null $depth

Return Value

void

at line 1499
static protected void addRepairNode(array $roots, array $childrenByParent, array $parentOrder, Model|stdClass $node, int|string|null $parentId)

Add a repair node to its parent bucket.

Parameters

array $roots
array $childrenByParent
array $parentOrder
Model|stdClass $node
int|string|null $parentId

Return Value

void

at line 1526
static protected void saveRepairNode(Model $model)

Save a node changed during repair.

Parameters

Model $model

Return Value

void

at line 1545
int rebuildTree(array $data, bool $delete = false, Model|null $root = null)

Rebuild the tree based on raw data.

If item data does not contain primary key, new node will be created.

Parameters

array $data
bool $delete

whether to delete nodes that exists but not in the data array

Model|null $root

Return Value

int

at line 1629
int rebuildSubtree(Model $root, array $data, bool $delete = false)

Rebuild a subtree from raw data.

Parameters

Model $root
array $data
bool $delete

Return Value

int

at line 1637
protected void buildRebuildDictionary(array $roots, array $childrenByParent, array $parentOrder, array $data, array $existing, array $scopeAttributes, int|string|null $parentId = null)

Build repair dictionaries from nested rebuild data.

Parameters

array $roots
array $childrenByParent
array $parentOrder
array $data
array $existing
array $scopeAttributes
int|string|null $parentId

Return Value

void

at line 1716
QueryBuilder applyNestedSetScope(string|null $table = null)

Apply the concrete tree scope.

Parameters

string|null $table

Return Value

QueryBuilder

at line 1727
Model|null root(array $columns = ['*'])

Get the root node.

Parameters

array $columns

Return Value

Model|null