class Builder implements Builder mixin Builder<int,

Forwarded query methods operate on this builder, so their value type is TModel.

Keep toBase() and getQuery() unparameterized because raw queries return stdClass rows.

Traits

Properties

protected Builder $query

The base query builder instance.

protected TModel $model

The model being queried.

array $pendingAttributes

The attributes that should be added to new models created by this builder.

protected array $eagerLoad

The relationships that should be eager loaded.

static protected array $macros

All of the globally registered builder macros.

protected array $localMacros

All of the locally registered builder macros.

protected Closure|null $onDelete

A replacement for the typical delete function.

protected list<string> $propertyPassthru

The properties that should be returned from query builder.

protected list<string> $passthru

The methods that should be returned from query builder.

protected array $scopes

Applied global scopes.

protected array $removedScopes

Removed global scopes.

protected Closure> $afterQueryCallbacks

The callbacks that should be invoked after retrieving data from the database.

protected Closure> $onCloneCallbacks

The callbacks that should be invoked on clone.

$this|HigherOrderBuilderProxy read-only $orWhere
$this|HigherOrderBuilderProxy read-only $whereNot
$this|HigherOrderBuilderProxy read-only $orWhereNot

Methods

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.

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

Execute the query and get the first result.

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

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

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.

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

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

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.

make(array $attributes = [])

Create and return an un-saved model instance.

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

Register a new global scope.

withoutGlobalScope(Scope|int|string $scope)

Remove a registered global scope.

withoutGlobalScopes(array|null $scopes = null)

Remove all or passed registered global scopes.

withoutGlobalScopesExcept(array $scopes = [])

Remove all global scopes except the given scopes.

array
removedScopes()

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

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

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

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

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

orWhereKey(mixed $id)

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

orWhereKeyNot(mixed $id)

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

except(mixed $models)

Exclude the given models from the query results.

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.

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.

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

Add an "or where" clause to the query.

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.

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

Add an "or where not" clause to the query.

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

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

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

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

hydrate(array $items)

Create a collection of models from plain arrays.

bool
fillAndInsert(array $values)

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

int
fillAndInsertOrIgnore(array $values)

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

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.

array
fillForInsert(array $values)

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

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

Create a collection of models from a raw query.

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

Find a model by its primary key.

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

Find a sole model by its primary key.

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

Find multiple models by their primary keys.

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

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

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

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

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

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

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

Get the first record matching the attributes or instantiate it.

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

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

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

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

void
ensureCanCreateOrFirst()

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

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

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

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.

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

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

mixed
value(Expression|string $column)

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

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.

mixed
valueOrFail(Expression|string $column)

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

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

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

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

Execute the query as a "select" statement.

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

Get the hydrated models without eager loading.

array
eagerLoadRelations(array $models)

Eager load the relationships for the models.

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

Eagerly load the relationship on a set of models.

getRelation(string $name)

Get the relation instance for the given relation name.

array
relationsNestedUnder(string $relation)

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

bool
isNestedUnder(string $relation, string $name)

Determine if the relationship is nested.

afterQuery(Closure $callback)

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

applyAfterQueryCallbacks(Collection $result)

Invoke the "after query" modification callbacks.

cursor()

Get a lazy collection for the given query.

void
enforceOrderBy()

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

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

Get a collection with the values of a given column.

array
modelKeys()

Get an array of primary keys from the query result.

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.

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

Paginate the given query into a simple paginator.

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

Paginate the given query into a cursor paginator.

ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

create(array $attributes = [])

Save a new model and return the instance.

createQuietly(array $attributes = [])

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

forceCreate(array $attributes)

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

forceCreateQuietly(array $attributes = [])

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

int
update(array $values)

Update records in the database.

int
updateFrom(array $values)

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

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

Insert new records or update the existing ones.

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

Update the column's update timestamp.

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

Increment a column's value by a given amount.

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

Decrement a column's value by a given amount.

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

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

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

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

array
addUpdatedAtColumn(array $values)

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

array
addUniqueIdsToUpsertValues(array $values)

Add unique IDs to the inserted values.

array
addTimestampsToUpsertValues(array $values)

Add timestamps to the inserted values.

array
addUpdatedAtToUpsertColumns(array $update)

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

mixed
delete()

Delete records from the database.

mixed
forceDelete()

Run the default delete function on the builder.

void
onDelete(Closure $callback)

Register a replacement for the default delete function.

bool
hasNamedScope(string $scope)

Determine if the given model has a scope.

mixed
scopes(array|string $scopes)

Call the given local model scopes.

applyScopes()

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

applyScopeCallback(callable $scope)

Apply a scope callback to the query.

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

Apply the given scope on the current builder instance.

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

Apply the given named scope on the current builder instance.

void
addNewWheresWithinGroup(Builder $query, int $originalWhereCount)

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

void
groupWhereSliceForScope(Builder $query, array $whereSlice)

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

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

Create a where array with nested where conditions.

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

Specify relationships that should be eager loaded.

without(mixed $relations)

Prevent the specified relations from being eager loaded.

withOnly(array|string $relations)

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

newModelInstance(array $attributes = [])

Create a new instance of the model being queried.

array
parseWithRelations(array $relations)

Parse a list of relations into individuals.

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

Prepare nested with relationships.

combineConstraints(array $constraints)

Combine an array of constraints into a single constraint.

array
parseNameAndAttributeSelectionConstraint(string $name)

Parse the attribute select constraints from the name.

array
createSelectWithConstraint(string $name)

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

array
addNestedWiths(string $name, array $results)

Parse the nested relationships in a relation.

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.

withCasts(array $casts)

Apply query-time casts to the model instance.

mixed
withSavepointIfNeeded(Closure $scope)

Execute the given Closure within a transaction savepoint if needed.

getUnionBuilders()

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

getQuery()

Get the underlying query builder instance.

setQuery(Builder $query)

Set the underlying query builder instance.

toBase()

Get a base query builder instance.

array
getEagerLoads()

Get the relationships being eagerly loaded.

setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

withoutEagerLoad(array $relations)

Indicate that the given relationships should not be eagerly loaded.

withoutEagerLoads()

Flush the relationships being eagerly loaded.

int|null
getLimit()

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

int|null
getOffset()

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

string
defaultKeyName()

Get the default key name of the table.

getModel()

Get the model instance being queried.

newQuery()

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

setModel(Model $model)

Set a model instance for the model being queried.

string
qualifyColumn(Expression|string $column)

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

array
qualifyColumns(array $columns)

Qualify the given columns with the model's table.

string|null
getTableAlias()

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

Closure|null
getMacro(string $name)

Get the given macro by name.

bool
hasMacro(string $name)

Checks if a macro is registered.

static Closure|null
getGlobalMacro(string $name)

Get the given global macro by name.

static bool
hasGlobalMacro(string $name)

Checks if a global macro is registered.

static void
flushState()

Flush all static state.

mixed
__get(string $key)

Dynamically access builder proxies.

mixed
__call(string $method, array $parameters)

Dynamically handle calls into the query instance.

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

Dynamically handle calls into the query instance.

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

Register the given mixin with the builder.

clone()

Clone the Eloquent query builder.

cloneWithout(array $properties)

Clone the Eloquent query builder without the given query properties.

cloneWithoutBindings(array $except)

Clone the Eloquent query builder without the given query bindings.

onClone(Closure $callback)

Register a closure to be invoked on a clone.

void
__clone()

Force a clone of the underlying query builder when cloning.

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

No description

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

No description

$this
fetchUsing(mixed ...$fetchUsing)

No description

$this
useWritePdo()

No description

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

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 42
bool chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

in BuildsQueries at line 99
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 117
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 135
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 145
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 155
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 227
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 245
LazyCollection lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

Parameters

int $chunkSize

Return Value

LazyCollection

in BuildsQueries at line 296
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 306
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 319
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 385
null|TValue first(array|string $columns = ['*'])

Execute the query and get the first result.

Parameters

array|string $columns

Return Value

null|TValue

at line 748
Model firstOrFail(array|string $columns = ['*'])

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

Parameters

array|string $columns

Return Value

Model

Exceptions

TModel>

at line 789
Model 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

Model

Exceptions

TModel>
MultipleRecordsFoundException

in BuildsQueries at line 439
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 538
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 560
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 570
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 580
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 593
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 608
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 115
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 128
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 138
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 151
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 163
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 177
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 190
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 203
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 217
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 292
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 314
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 328
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 339
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 353
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 367
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 381
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 395
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 408
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 422
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 440
QueriesRelationships orWhereRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

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

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 459
QueriesRelationships whereDoesntHaveRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add a basic count / exists condition to a relationship query.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 478
QueriesRelationships orWhereDoesntHaveRelation(Relation|string $relation, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

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

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 498
QueriesRelationships whereMorphRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add a polymorphic relationship condition to the query with a where clause.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 514
QueriesRelationships orWhereMorphRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

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

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 530
QueriesRelationships whereMorphDoesntHaveRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add a polymorphic relationship condition to the query with a doesn't have clause.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 546
QueriesRelationships orWhereMorphDoesntHaveRelation(MorphTo|string $relation, string|array $types, Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null)

Add a polymorphic relationship condition to the query with an "or doesn't have" clause.

Parameters

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

Return Value

QueriesRelationships

in QueriesRelationships at line 562
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 607
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 652
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 663
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 673
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 698
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 738
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 751
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 789
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 797
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 899
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 913
QueriesRelationships withCount(mixed $relations)

Add subselect queries to count the relations.

Parameters

mixed $relations

Return Value

QueriesRelationships

in QueriesRelationships at line 921
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 929
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 937
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 945
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 953
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 964
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 981
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 1008
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 1022
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 1039
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 1053
protected Relation getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

Parameters

string $relation

Return Value

Relation

in QueriesRelationships at line 1063
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

at line 180
__construct(Builder $query)

Create a new Eloquent query builder instance.

Parameters

Builder $query

at line 190
Model make(array $attributes = [])

Create and return an un-saved model instance.

Parameters

array $attributes

Return Value

Model

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

Register a new global scope.

Parameters

int|string $identifier
Closure|Scope $scope

Return Value

Builder

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

Remove a registered global scope.

Parameters

Scope|int|string $scope

Return Value

Builder

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

Remove all or passed registered global scopes.

Parameters

array|null $scopes

Return Value

Builder

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

Remove all global scopes except the given scopes.

Parameters

array $scopes

Return Value

Builder

at line 256
array removedScopes()

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

Return Value

array

at line 266
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

at line 300
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

at line 310
Builder orWhereKey(mixed $id)

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

Parameters

mixed $id

Return Value

Builder

at line 320
Builder orWhereKeyNot(mixed $id)

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

Parameters

mixed $id

Return Value

Builder

at line 328
Builder except(mixed $models)

Exclude the given models from the query results.

Parameters

mixed $models

Return Value

Builder

at line 343
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

at line 368
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

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

Add an "or where" clause to the query.

Parameters

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

Return Value

Builder

at line 394
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

at line 404
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

at line 412
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

at line 426
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

at line 442
Collection hydrate(array $items)

Create a collection of models from plain arrays.

Parameters

array $items

Return Value

Collection

at line 462
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

at line 472
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

at line 482
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

at line 493
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

at line 520
Collection fromQuery(string $query, array $bindings = [])

Create a collection of models from a raw query.

Parameters

string $query
array $bindings

Return Value

Collection

at line 532
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

at line 549
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

at line 559
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

at line 577
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>

at line 613
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

at line 637
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

at line 658
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

at line 673
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

at line 692
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

at line 708
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

at line 718
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

at line 732
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

at line 766
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

at line 801
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

at line 816
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

at line 826
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>

at line 834
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

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

Execute the query as a "select" statement.

Parameters

array|string $columns

Return Value

Collection

at line 871
array getModels(array|string $columns = ['*'])

Get the hydrated models without eager loading.

Parameters

array|string $columns

Return Value

array

at line 884
array eagerLoadRelations(array $models)

Eager load the relationships for the models.

Parameters

array $models

Return Value

array

at line 901
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

at line 927
Relation getRelation(string $name)

Get the relation instance for the given relation name.

Parameters

string $name

Return Value

Relation

at line 955
protected array relationsNestedUnder(string $relation)

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

Parameters

string $relation

Return Value

array

at line 974
protected bool isNestedUnder(string $relation, string $name)

Determine if the relationship is nested.

Parameters

string $relation
string $name

Return Value

bool

at line 982
Builder afterQuery(Closure $callback)

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

Parameters

Closure $callback

Return Value

Builder

at line 999
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

at line 1013
LazyCollection cursor()

Get a lazy collection for the given query.

Return Value

LazyCollection

at line 1025
protected void enforceOrderBy()

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

Return Value

void

at line 1037
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

at line 1070
array modelKeys()

Get an array of primary keys from the query result.

Return Value

array

at line 1082
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

at line 1105
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

at line 1127
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

at line 1137
protected Collection ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

Parameters

bool $shouldReverse

Return Value

Collection

at line 1170
Model create(array $attributes = [])

Save a new model and return the instance.

Parameters

array $attributes

Return Value

Model

at line 1182
Model createQuietly(array $attributes = [])

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

Parameters

array $attributes

Return Value

Model

at line 1192
Model forceCreate(array $attributes)

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

Parameters

array $attributes

Return Value

Model

at line 1204
Model forceCreateQuietly(array $attributes = [])

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

Parameters

array $attributes

Return Value

Model

at line 1212
int update(array $values)

Update records in the database.

Parameters

array $values

Return Value

int

at line 1220
int updateFrom(array $values)

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

Parameters

array $values

Return Value

int

at line 1228
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

at line 1252
false|int touch(array|string|null $column = null)

Update the column's update timestamp.

Parameters

array|string|null $column

Return Value

false|int

at line 1276
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

at line 1288
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

at line 1303
int incrementEach(array $columns, array $extra = [])

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

Parameters

array $columns
array $extra

Return Value

int

at line 1317
int decrementEach(array $columns, array $extra = [])

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

Parameters

array $columns
array $extra

Return Value

int

at line 1328
protected array addUpdatedAtColumn(array $values)

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

Parameters

array $values

Return Value

array

at line 1372
protected array addUniqueIdsToUpsertValues(array $values)

Add unique IDs to the inserted values.

Parameters

array $values

Return Value

array

at line 1392
protected array addTimestampsToUpsertValues(array $values)

Add timestamps to the inserted values.

Parameters

array $values

Return Value

array

at line 1417
protected array addUpdatedAtToUpsertColumns(array $update)

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

Parameters

array $update

Return Value

array

at line 1444
mixed delete()

Delete records from the database.

Return Value

mixed

at line 1458
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

at line 1466
void onDelete(Closure $callback)

Register a replacement for the default delete function.

Parameters

Closure $callback

Return Value

void

at line 1474
bool hasNamedScope(string $scope)

Determine if the given model has a scope.

Parameters

string $scope

Return Value

bool

at line 1482
mixed scopes(array|string $scopes)

Call the given local model scopes.

Parameters

array|string $scopes

Return Value

mixed

at line 1509
Builder applyScopes()

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

Return Value

Builder

at line 1549
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

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

Apply the given scope on the current builder instance.

Parameters

callable $scope
array $parameters

Return Value

mixed

at line 1582
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

at line 1592
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

at line 1615
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

at line 1632
protected array createNestedWhere(array $whereSlice, string $boolean = 'and')

Create a where array with nested where conditions.

Parameters

array $whereSlice
string $boolean

Return Value

array

at line 1647
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

at line 1663
Builder without(mixed $relations)

Prevent the specified relations from being eager loaded.

Parameters

mixed $relations

Return Value

Builder

at line 1677
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

at line 1689
Model newModelInstance(array $attributes = [])

Create a new instance of the model being queried.

Parameters

array $attributes

Return Value

Model

at line 1701
protected array parseWithRelations(array $relations)

Parse a list of relations into individuals.

Parameters

array $relations

Return Value

array

at line 1724
protected array prepareNestedWithRelationships(array $relations, string $prefix = '')

Prepare nested with relationships.

Parameters

array $relations
string $prefix

Return Value

array

at line 1772
protected Closure combineConstraints(array $constraints)

Combine an array of constraints into a single constraint.

Parameters

array $constraints

Return Value

Closure

at line 1786
protected array parseNameAndAttributeSelectionConstraint(string $name)

Parse the attribute select constraints from the name.

Parameters

string $name

Return Value

array

at line 1797
protected array createSelectWithConstraint(string $name)

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

Parameters

string $name

Return Value

array

at line 1811
protected array addNestedWiths(string $name, array $results)

Parse the nested relationships in a relation.

Parameters

string $name
array $results

Return Value

array

at line 1835
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

at line 1855
Builder withCasts(array $casts)

Apply query-time casts to the model instance.

Parameters

array $casts

Return Value

Builder

at line 1870
mixed withSavepointIfNeeded(Closure $scope)

Execute the given Closure within a transaction savepoint if needed.

Parameters

Closure $scope

Return Value

mixed

at line 1880
protected Collection getUnionBuilders()

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

Return Value

Collection

at line 1890
Builder getQuery()

Get the underlying query builder instance.

Return Value

Builder

at line 1898
Builder setQuery(Builder $query)

Set the underlying query builder instance.

Parameters

Builder $query

Return Value

Builder

at line 1908
Builder toBase()

Get a base query builder instance.

Return Value

Builder

at line 1916
array getEagerLoads()

Get the relationships being eagerly loaded.

Return Value

array

at line 1924
Builder setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

Parameters

array $eagerLoad

Return Value

Builder

at line 1934
Builder withoutEagerLoad(array $relations)

Indicate that the given relationships should not be eagerly loaded.

Parameters

array $relations

Return Value

Builder

at line 1944
Builder withoutEagerLoads()

Flush the relationships being eagerly loaded.

Return Value

Builder

at line 1952
int|null getLimit()

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

Return Value

int|null

at line 1960
int|null getOffset()

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

Return Value

int|null

at line 1968
protected string defaultKeyName()

Get the default key name of the table.

Return Value

string

at line 1978
Model getModel()

Get the model instance being queried.

Return Value

Model

at line 1988
Builder newQuery()

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

Return Value

Builder

at line 2001
Builder setModel(Model $model)

Set a model instance for the model being queried.

Parameters

Model $model

Return Value

Builder

at line 2014
string qualifyColumn(Expression|string $column)

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

Parameters

Expression|string $column

Return Value

string

at line 2034
array qualifyColumns(array $columns)

Qualify the given columns with the model's table.

Parameters

array $columns

Return Value

array

at line 2048
protected string|null getTableAlias()

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

Return Value

string|null

at line 2056
Closure|null getMacro(string $name)

Get the given macro by name.

Parameters

string $name

Return Value

Closure|null

at line 2064
bool hasMacro(string $name)

Checks if a macro is registered.

Parameters

string $name

Return Value

bool

at line 2072
static Closure|null getGlobalMacro(string $name)

Get the given global macro by name.

Parameters

string $name

Return Value

Closure|null

at line 2080
static bool hasGlobalMacro(string $name)

Checks if a global macro is registered.

Parameters

string $name

Return Value

bool

at line 2088
static void flushState()

Flush all static state.

Return Value

void

at line 2098
mixed __get(string $key)

Dynamically access builder proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

at line 2114
mixed __call(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

at line 2156
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 2188
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

at line 2204
Builder clone()

Clone the Eloquent query builder.

Return Value

Builder

at line 2212
Builder cloneWithout(array $properties)

Clone the Eloquent query builder without the given query properties.

Parameters

array $properties

Return Value

Builder

at line 2224
Builder cloneWithoutBindings(array $except)

Clone the Eloquent query builder without the given query bindings.

Parameters

array $except

Return Value

Builder

at line 2234
Builder onClone(Closure $callback)

Register a closure to be invoked on a clone.

Parameters

Closure $callback

Return Value

Builder

at line 2244
void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void

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

No description

Parameters

UnitEnum|string $ability
mixed $user

Return Value

$this

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

No description

Parameters

UnitEnum|string> $abilities
mixed $user

Return Value

$this

at line 55
$this fetchUsing(mixed ...$fetchUsing)

No description

Parameters

mixed ...$fetchUsing

Return Value

$this

at line 55
$this useWritePdo()

No description

Return Value

$this