class Builder implements Builder (View source)

Traits

Properties

protected Builder $query

The base query builder instance.

protected Model $model

The model being queried.

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 $onDelete

A replacement for the typical delete function.

protected array $scopes

Applied global scopes.

protected array $removedScopes

Removed global scopes.

HigherOrderBuilderProxy read-only $orWhere

Methods

$this|TWhenReturnType
when(bool $value, callable $callback = null, callable $default = null)

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

$this|TUnlessReturnType
unless(bool $value, callable $callback = null, callable $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
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($chunkSize = 1000, string|null $column = null, string|null $alias = null)

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

lazyByIdDesc($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($chunkSize = 1000, string|null $column = null, string|null $alias = null, bool $descending = false)

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

Model|object|BuildsQueries|null
first(array|string $columns = ['*'])

Execute the query and get the first result.

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

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

paginateUsingCursor(int $perPage, array $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 $cursor, array $options)

Create a new cursor paginator instance.

$this
tap(callable $callback)

Pass the query to a given callback.

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 void
throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

toBase()

Get a base query builder instance.

select($columns = ['*'])

{@inheritdoc}

selectSub($query, $as)

{@inheritdoc}

selectRaw($expression, array $bindings = [])

{@inheritdoc}

fromSub($query, $as)

{@inheritdoc}

fromRaw($expression, $bindings = [])

{@inheritdoc}

addSelect($column)

{@inheritdoc}

distinct()

{@inheritdoc}

from($table, $as = null)

{@inheritdoc}

join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)

{@inheritdoc}

joinWhere($table, $first, $operator, $second, $type = 'inner')

{@inheritdoc}

joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)

{@inheritdoc}

leftJoin($table, $first, $operator = null, $second = null)

{@inheritdoc}

leftJoinWhere($table, $first, $operator, $second)

{@inheritdoc}

leftJoinSub($query, $as, $first, $operator = null, $second = null)

{@inheritdoc}

rightJoin($table, $first, $operator = null, $second = null)

{@inheritdoc}

rightJoinWhere($table, $first, $operator, $second)

{@inheritdoc}

rightJoinSub($query, $as, $first, $operator = null, $second = null)

{@inheritdoc}

crossJoin($table, $first = null, $operator = null, $second = null)

{@inheritdoc}

crossJoinSub($query, $as)

{@inheritdoc}

mergeWheres($wheres, $bindings)

{@inheritdoc}

where(Closure|Builder|string|array $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic where clause to the query.

prepareValueAndOperator($value, $operator, $useDefault = false)

{@inheritdoc}

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

Add an "or where" clause to the query.

whereColumn($first, $operator = null, $second = null, $boolean = 'and')

{@inheritdoc}

orWhereColumn($first, $operator = null, $second = null)

{@inheritdoc}

whereRaw($sql, $bindings = [], $boolean = 'and')

{@inheritdoc}

orWhereRaw($sql, $bindings = [])

{@inheritdoc}

whereIn($column, $values, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereIn($column, $values)

{@inheritdoc}

whereNotIn($column, $values, $boolean = 'and')

{@inheritdoc}

orWhereNotIn($column, $values)

{@inheritdoc}

whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereIntegerInRaw($column, $values)

{@inheritdoc}

whereIntegerNotInRaw($column, $values, $boolean = 'and')

{@inheritdoc}

orWhereIntegerNotInRaw($column, $values)

{@inheritdoc}

whereNull($columns, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereNull($column)

{@inheritdoc}

whereNotNull($columns, $boolean = 'and')

{@inheritdoc}

whereBetween($column, iterable $values, $boolean = 'and', $not = false)

{@inheritdoc}

whereBetweenColumns($column, array $values, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereBetween($column, iterable $values)

{@inheritdoc}

orWhereBetweenColumns($column, array $values)

{@inheritdoc}

whereNotBetween($column, iterable $values, $boolean = 'and')

{@inheritdoc}

whereNotBetweenColumns($column, array $values, $boolean = 'and')

{@inheritdoc}

orWhereNotBetween($column, iterable $values)

{@inheritdoc}

orWhereNotBetweenColumns($column, array $values)

{@inheritdoc}

orWhereNotNull($column)

{@inheritdoc}

whereDate($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereDate($column, $operator, $value = null)

{@inheritdoc}

whereTime($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereTime($column, $operator, $value = null)

{@inheritdoc}

whereDay($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereDay($column, $operator, $value = null)

{@inheritdoc}

whereMonth($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereMonth($column, $operator, $value = null)

{@inheritdoc}

whereYear($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereYear($column, $operator, $value = null)

{@inheritdoc}

whereNested(Closure $callback, $boolean = 'and')

{@inheritdoc}

addNestedWhereQuery($query, $boolean = 'and')

{@inheritdoc}

whereExists(Closure $callback, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereExists(Closure $callback, $not = false)

{@inheritdoc}

whereNotExists(Closure $callback, $boolean = 'and')

{@inheritdoc}

orWhereNotExists(Closure $callback)

{@inheritdoc}

whereRowValues($columns, $operator, $values, $boolean = 'and')

{@inheritdoc}

orWhereRowValues($columns, $operator, $values)

{@inheritdoc}

whereJsonContains($column, $value, $boolean = 'and', $not = false)

{@inheritdoc}

orWhereJsonContains($column, $value)

{@inheritdoc}

whereJsonDoesntContain($column, $value, $boolean = 'and')

{@inheritdoc}

orWhereJsonDoesntContain($column, $value)

{@inheritdoc}

whereJsonLength($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

orWhereJsonLength($column, $operator, $value = null)

{@inheritdoc}

groupBy(...$groups)

{@inheritdoc}

groupByRaw($sql, array $bindings = [])

{@inheritdoc}

having($column, $operator = null, $value = null, $boolean = 'and')

{@inheritdoc}

orHaving($column, $operator = null, $value = null)

{@inheritdoc}

havingNull($columns, $boolean = 'and', $not = false)

{@inheritdoc}

orHavingNull($column)

{@inheritdoc}

havingNotNull($columns, $boolean = 'and')

No description

orHavingNotNull($column)

No description

havingBetween($column, array $values, $boolean = 'and', $not = false)

No description

havingRaw($sql, array $bindings = [], $boolean = 'and')

No description

orHavingRaw($sql, array $bindings = [])

No description

orderBy($column, $direction = 'asc')

No description

orderByDesc($column)

No description

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

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

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

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

inRandomOrder($seed = '')

No description

orderByRaw($sql, $bindings = [])

No description

skip($value)

No description

offset($value)

No description

take($value)

No description

limit($value)

No description

forPage($page, $perPage = 15)

No description

forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')

No description

forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')

No description

reorder($column = null, $direction = 'asc')

No description

union($query, $all = false)

No description

unionAll($query)

No description

lock($value = true)

No description

lockForUpdate()

No description

sharedLock()

No description

toSql()

No description

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

Find a model by its primary key.

mixed
value(string|Expression $column)

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

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

Execute the query as a "select" statement.

cursor()

Get a lazy collection for the given query.

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

Get an array with the values of a given column.

implode($column, $glue = '')

No description

exists()

No description

doesntExist()

No description

existsOr(Closure $callback)

No description

doesntExistOr(Closure $callback)

No description

count($columns = '*')

No description

min($column)

No description

max($column)

No description

sum($column)

No description

avg($column)

No description

average($column)

No description

aggregate($function, $columns = ['*'])

No description

numericAggregate($function, $columns = ['*'])

No description

insert(array $values)

No description

insertOrIgnore(array $values)

No description

insertGetId(array $values, $sequence = null)

No description

insertUsing(array $columns, $query)

No description

int
update(array $values)

Update records in the database.

updateOrInsert(array $attributes, array $values = [])

No description

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

Insert new records or update the existing ones.

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

Increment a column's value by a given amount.

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

Decrement a column's value by a given amount.

mixed
delete()

Delete records from the database.

truncate()

No description

newQuery()

No description

raw($value)

No description

getBindings()

No description

getRawBindings()

No description

setBindings(array $bindings, $type = 'where')

No description

addBinding($value, $type = 'where')

No description

mergeBindings(Builder $query)

No description

cleanBindings(array $bindings)

No description

getConnection()

No description

getProcessor()

No description

getGrammar()

No description

useWritePdo()

No description

clone()

Clone the Eloquent query builder.

cloneWithout(array $properties)

No description

cloneWithoutBindings(array $except)

No description

mixed
__call(string $method, array $parameters)

Dynamically handle calls into the query instance.

explain()

Explains the query.

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

Add a relationship count / exists condition to the query.

hasNested(string $relations, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure|null $callback = null)

Add nested relationship count / exists conditions to the query.

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

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

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

Add a relationship count / exists condition to the query.

orDoesntHave(string $relation)

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

whereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)

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

orWhereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)

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

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

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

orWhereDoesntHave(string $relation, Closure $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 = '>=', int $count = 1, string $boolean = 'and', Closure $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 = '>=', 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 $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 $callback = null, string $operator = '>=', int $count = 1)

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

orWhereHasMorph(MorphTo|string $relation, string|array $types, Closure $callback = null, string $operator = '>=', int $count = 1)

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

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

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

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

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

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

Add a basic where clause to a relationship query.

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

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

Add a morph-to relationship condition to the query.

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

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

$this
whereBelongsTo(Model $related, $relationshipName = null, string $boolean = 'and')

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

$this
orWhereBelongsTo(Model $related, $relationshipName = null)

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

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

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

$this
withCount(mixed $relations)

Add subselect queries to count the relations.

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

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

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

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

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

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

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

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

$this
withExists(string|array $relation)

Add subselect queries to include the existence of related models.

addHasWhere(Builder $hasQuery, Relation $relation, string $operator, 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.

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

Add a sub-query count clause to this query.

getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

bool
canUseExistsForExistenceCheck(string $operator, int $count)

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

void
__construct(Builder $query)

Create a new Eloquent query builder instance.

make(array $attributes = [])

Create and return an un-saved model instance.

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

Register a new global scope.

$this
withoutGlobalScope(Scope|string $scope)

Remove a registered global scope.

$this
withoutGlobalScopes(array $scopes = null)

Remove all or passed registered global scopes.

array
removedScopes()

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

$this
whereKey(mixed $id)

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

$this
whereKeyNot(mixed $id)

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

Model|Builder|null
firstWhere(Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic where clause to the query, and return the first result.

hydrate(array $items)

Create a collection of models from plain arrays.

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

Create a collection of models from a raw query.

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

Find multiple models by their primary keys.

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

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

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

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

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

Get the first record matching the attributes or instantiate it.

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

Get the first record matching the attributes or create it.

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

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

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

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

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

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

mixed
valueOrFail(string|Expression $column)

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

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.

void
enforceOrderBy()

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

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

Paginate the given query.

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

Paginate the given query into a simple paginator.

cursorPaginate(int|null $perPage = null, array $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.

Model|$this
create(array $attributes = [])

Save a new model and return the instance.

Model|$this
forceCreate(array $attributes)

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

array
addUpdatedAtColumn(array $values)

Add the "updated at" column to an array of 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
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.

Builder|mixed
scopes(array|string $scopes)

Call the given local model scopes.

applyScopes()

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

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.

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

Set the relationships that should be eager loaded.

$this
without(mixed $relations)

Prevent the specified relations from being eager loaded.

$this
withOnly(mixed $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
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.

$this
withCasts(array $casts)

Apply query-time casts to the model instance.

getQuery()

Get the underlying query builder instance.

$this
setQuery(Builder $query)

Set the underlying query builder instance.

array
getEagerLoads()

Get the relationships being eagerly loaded.

$this
setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

string
defaultKeyName()

Get the default key name of the table.

getModel()

Get the model instance being queried.

$this
setModel(Model $model)

Set a model instance for the model being queried.

string
qualifyColumn(string|Expression $column)

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

array
qualifyColumns(array|Expression $columns)

Qualify the given columns with the model's table.

getMacro(string $name)

Get the given macro by name.

bool
hasMacro(string $name)

Checks if a macro is registered.

static Closure
getGlobalMacro(string $name)

Get the given global macro by name.

static bool
hasGlobalMacro(string $name)

Checks if a global macro is registered.

mixed
__get(string $key)

Dynamically access builder proxies.

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

Dynamically handle calls into the query instance.

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

Register the given mixin with the builder.

void
__clone()

Force a clone of the underlying query builder when cloning.

Details

$this|TWhenReturnType when(bool $value, callable $callback = null, callable $default = null)

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

Parameters

bool $value
callable $callback
callable $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless(bool $value, callable $callback = null, callable $default = null)

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

Parameters

bool $value
callable $callback
callable $default

Return Value

$this|TUnlessReturnType

bool chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

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

Run a map over each item while chunking.

Parameters

callable $callback
int $count

Return Value

Collection

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

Execute a callback over each item while chunking.

Parameters

callable $callback
int $count

Return Value

bool

Exceptions

RuntimeException

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

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

LazyCollection lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

Parameters

int $chunkSize

Return Value

LazyCollection

Exceptions

InvalidArgumentException

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

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

Parameters

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

Return Value

LazyCollection

Exceptions

InvalidArgumentException

LazyCollection lazyByIdDesc($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

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

Return Value

LazyCollection

Exceptions

InvalidArgumentException

protected LazyCollection orderedLazyById($chunkSize = 1000, string|null $column = null, string|null $alias = null, bool $descending = false)

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

Parameters

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

Return Value

LazyCollection

Exceptions

InvalidArgumentException

Model|object|BuildsQueries|null first(array|string $columns = ['*'])

Execute the query and get the first result.

Parameters

array|string $columns

Return Value

Model|object|BuildsQueries|null

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

ModelNotFoundException
MultipleRecordsFoundException

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

Paginate the given query using a cursor paginator.

Parameters

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

Return Value

CursorPaginator

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

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

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

protected CursorPaginator cursorPaginator(Collection $items, int $perPage, Cursor $cursor, array $options)

Create a new cursor paginator instance.

Parameters

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

Return Value

CursorPaginator

$this tap(callable $callback)

Pass the query to a given callback.

Parameters

callable $callback

Return Value

$this

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

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

static protected void throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

void

Exceptions

BadMethodCallException

Builder toBase()

Get a base query builder instance.

Return Value

Builder

select($columns = ['*'])

{@inheritdoc}

Parameters

$columns

selectSub($query, $as)

{@inheritdoc}

Parameters

$query
$as

selectRaw($expression, array $bindings = [])

{@inheritdoc}

Parameters

$expression
array $bindings

fromSub($query, $as)

{@inheritdoc}

Parameters

$query
$as

fromRaw($expression, $bindings = [])

{@inheritdoc}

Parameters

$expression
$bindings

addSelect($column)

{@inheritdoc}

Parameters

$column

distinct()

{@inheritdoc}

from($table, $as = null)

{@inheritdoc}

Parameters

$table
$as

join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)

{@inheritdoc}

Parameters

$table
$first
$operator
$second
$type
$where

joinWhere($table, $first, $operator, $second, $type = 'inner')

{@inheritdoc}

Parameters

$table
$first
$operator
$second
$type

joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)

{@inheritdoc}

Parameters

$query
$as
$first
$operator
$second
$type
$where

leftJoin($table, $first, $operator = null, $second = null)

{@inheritdoc}

Parameters

$table
$first
$operator
$second

leftJoinWhere($table, $first, $operator, $second)

{@inheritdoc}

Parameters

$table
$first
$operator
$second

leftJoinSub($query, $as, $first, $operator = null, $second = null)

{@inheritdoc}

Parameters

$query
$as
$first
$operator
$second

rightJoin($table, $first, $operator = null, $second = null)

{@inheritdoc}

Parameters

$table
$first
$operator
$second

rightJoinWhere($table, $first, $operator, $second)

{@inheritdoc}

Parameters

$table
$first
$operator
$second

rightJoinSub($query, $as, $first, $operator = null, $second = null)

{@inheritdoc}

Parameters

$query
$as
$first
$operator
$second

crossJoin($table, $first = null, $operator = null, $second = null)

{@inheritdoc}

Parameters

$table
$first
$operator
$second

crossJoinSub($query, $as)

{@inheritdoc}

Parameters

$query
$as

mergeWheres($wheres, $bindings)

{@inheritdoc}

Parameters

$wheres
$bindings

Builder where(Closure|Builder|string|array $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic where clause to the query.

Parameters

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

Return Value

Builder

prepareValueAndOperator($value, $operator, $useDefault = false)

{@inheritdoc}

Parameters

$value
$operator
$useDefault

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

Add an "or where" clause to the query.

Parameters

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

Return Value

Builder

whereColumn($first, $operator = null, $second = null, $boolean = 'and')

{@inheritdoc}

Parameters

$first
$operator
$second
$boolean

orWhereColumn($first, $operator = null, $second = null)

{@inheritdoc}

Parameters

$first
$operator
$second

whereRaw($sql, $bindings = [], $boolean = 'and')

{@inheritdoc}

Parameters

$sql
$bindings
$boolean

orWhereRaw($sql, $bindings = [])

{@inheritdoc}

Parameters

$sql
$bindings

whereIn($column, $values, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$column
$values
$boolean
$not

orWhereIn($column, $values)

{@inheritdoc}

Parameters

$column
$values

whereNotIn($column, $values, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$values
$boolean

orWhereNotIn($column, $values)

{@inheritdoc}

Parameters

$column
$values

whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$column
$values
$boolean
$not

orWhereIntegerInRaw($column, $values)

{@inheritdoc}

Parameters

$column
$values

whereIntegerNotInRaw($column, $values, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$values
$boolean

orWhereIntegerNotInRaw($column, $values)

{@inheritdoc}

Parameters

$column
$values

whereNull($columns, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$columns
$boolean
$not

orWhereNull($column)

{@inheritdoc}

Parameters

$column

whereNotNull($columns, $boolean = 'and')

{@inheritdoc}

Parameters

$columns
$boolean

whereBetween($column, iterable $values, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$column
iterable $values
$boolean
$not

whereBetweenColumns($column, array $values, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$column
array $values
$boolean
$not

orWhereBetween($column, iterable $values)

{@inheritdoc}

Parameters

$column
iterable $values

orWhereBetweenColumns($column, array $values)

{@inheritdoc}

Parameters

$column
array $values

whereNotBetween($column, iterable $values, $boolean = 'and')

{@inheritdoc}

Parameters

$column
iterable $values
$boolean

whereNotBetweenColumns($column, array $values, $boolean = 'and')

{@inheritdoc}

Parameters

$column
array $values
$boolean

orWhereNotBetween($column, iterable $values)

{@inheritdoc}

Parameters

$column
iterable $values

orWhereNotBetweenColumns($column, array $values)

{@inheritdoc}

Parameters

$column
array $values

orWhereNotNull($column)

{@inheritdoc}

Parameters

$column

whereDate($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereDate($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

whereTime($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereTime($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

whereDay($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereDay($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

whereMonth($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereMonth($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

whereYear($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereYear($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

whereNested(Closure $callback, $boolean = 'and')

{@inheritdoc}

Parameters

Closure $callback
$boolean

addNestedWhereQuery($query, $boolean = 'and')

{@inheritdoc}

Parameters

$query
$boolean

whereExists(Closure $callback, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

Closure $callback
$boolean
$not

orWhereExists(Closure $callback, $not = false)

{@inheritdoc}

Parameters

Closure $callback
$not

whereNotExists(Closure $callback, $boolean = 'and')

{@inheritdoc}

Parameters

Closure $callback
$boolean

orWhereNotExists(Closure $callback)

{@inheritdoc}

Parameters

Closure $callback

whereRowValues($columns, $operator, $values, $boolean = 'and')

{@inheritdoc}

Parameters

$columns
$operator
$values
$boolean

orWhereRowValues($columns, $operator, $values)

{@inheritdoc}

Parameters

$columns
$operator
$values

whereJsonContains($column, $value, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$column
$value
$boolean
$not

orWhereJsonContains($column, $value)

{@inheritdoc}

Parameters

$column
$value

whereJsonDoesntContain($column, $value, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$value
$boolean

orWhereJsonDoesntContain($column, $value)

{@inheritdoc}

Parameters

$column
$value

whereJsonLength($column, $operator, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orWhereJsonLength($column, $operator, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

groupBy(...$groups)

{@inheritdoc}

Parameters

...$groups

groupByRaw($sql, array $bindings = [])

{@inheritdoc}

Parameters

$sql
array $bindings

having($column, $operator = null, $value = null, $boolean = 'and')

{@inheritdoc}

Parameters

$column
$operator
$value
$boolean

orHaving($column, $operator = null, $value = null)

{@inheritdoc}

Parameters

$column
$operator
$value

havingNull($columns, $boolean = 'and', $not = false)

{@inheritdoc}

Parameters

$columns
$boolean
$not

orHavingNull($column)

{@inheritdoc}

Parameters

$column

havingNotNull($columns, $boolean = 'and')

No description

Parameters

$columns
$boolean

orHavingNotNull($column)

No description

Parameters

$column

havingBetween($column, array $values, $boolean = 'and', $not = false)

No description

Parameters

$column
array $values
$boolean
$not

havingRaw($sql, array $bindings = [], $boolean = 'and')

No description

Parameters

$sql
array $bindings
$boolean

orHavingRaw($sql, array $bindings = [])

No description

Parameters

$sql
array $bindings

orderBy($column, $direction = 'asc')

No description

Parameters

$column
$direction

orderByDesc($column)

No description

Parameters

$column

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

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

Parameters

Closure|Expression|Builder|string $column

Return Value

Builder

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

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

Parameters

Closure|Expression|Builder|string $column

Return Value

Builder

inRandomOrder($seed = '')

No description

Parameters

$seed

orderByRaw($sql, $bindings = [])

No description

Parameters

$sql
$bindings

skip($value)

No description

Parameters

$value

offset($value)

No description

Parameters

$value

take($value)

No description

Parameters

$value

limit($value)

No description

Parameters

$value

forPage($page, $perPage = 15)

No description

Parameters

$page
$perPage

forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')

No description

Parameters

$perPage
$lastId
$column

forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')

No description

Parameters

$perPage
$lastId
$column

reorder($column = null, $direction = 'asc')

No description

Parameters

$column
$direction

union($query, $all = false)

No description

Parameters

$query
$all

unionAll($query)

No description

Parameters

$query

lock($value = true)

No description

Parameters

$value

lockForUpdate()

No description

sharedLock()

No description

toSql()

No description

Model|Collection|Builder[]|Builder|null find(mixed $id, array $columns = ['*'])

Find a model by its primary key.

Parameters

mixed $id
array $columns

Return Value

Model|Collection|Builder[]|Builder|null

mixed value(string|Expression $column)

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

Parameters

string|Expression $column

Return Value

mixed

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

Execute the query as a "select" statement.

Parameters

array|string $columns

Return Value

Collection|Builder[]

LazyCollection cursor()

Get a lazy collection for the given query.

Return Value

LazyCollection

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

Get an array with the values of a given column.

Parameters

string|Expression $column
string|null $key

Return Value

Collection

implode($column, $glue = '')

No description

Parameters

$column
$glue

exists()

No description

doesntExist()

No description

existsOr(Closure $callback)

No description

Parameters

Closure $callback

doesntExistOr(Closure $callback)

No description

Parameters

Closure $callback

count($columns = '*')

No description

Parameters

$columns

min($column)

No description

Parameters

$column

max($column)

No description

Parameters

$column

sum($column)

No description

Parameters

$column

avg($column)

No description

Parameters

$column

average($column)

No description

Parameters

$column

aggregate($function, $columns = ['*'])

No description

Parameters

$function
$columns

numericAggregate($function, $columns = ['*'])

No description

Parameters

$function
$columns

insert(array $values)

No description

Parameters

array $values

insertOrIgnore(array $values)

No description

Parameters

array $values

insertGetId(array $values, $sequence = null)

No description

Parameters

array $values
$sequence

insertUsing(array $columns, $query)

No description

Parameters

array $columns
$query

int update(array $values)

Update records in the database.

Parameters

array $values

Return Value

int

updateOrInsert(array $attributes, array $values = [])

No description

Parameters

array $attributes
array $values

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

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

Increment a column's value by a given amount.

Parameters

string|Expression $column
float|int $amount
array $extra

Return Value

int

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

Decrement a column's value by a given amount.

Parameters

string|Expression $column
float|int $amount
array $extra

Return Value

int

mixed delete()

Delete records from the database.

Return Value

mixed

truncate()

No description

newQuery()

No description

raw($value)

No description

Parameters

$value

getBindings()

No description

getRawBindings()

No description

setBindings(array $bindings, $type = 'where')

No description

Parameters

array $bindings
$type

addBinding($value, $type = 'where')

No description

Parameters

$value
$type

mergeBindings(Builder $query)

No description

Parameters

Builder $query

cleanBindings(array $bindings)

No description

Parameters

array $bindings

getConnection()

No description

getProcessor()

No description

getGrammar()

No description

useWritePdo()

No description

Builder clone()

Clone the Eloquent query builder.

Return Value

Builder

cloneWithout(array $properties)

No description

Parameters

array $properties

cloneWithoutBindings(array $except)

No description

Parameters

array $except

mixed __call(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

Collection explain()

Explains the query.

Return Value

Collection

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

Add a relationship count / exists condition to the query.

Parameters

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

Return Value

Builder|QueriesRelationships

Exceptions

RuntimeException

protected Builder|QueriesRelationships hasNested(string $relations, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure|null $callback = null)

Add nested relationship count / exists conditions to the query.

Sets up recursive call to whereHas until we finish the nested relation.

Parameters

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

Return Value

Builder|QueriesRelationships

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

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

Parameters

string $relation
string $operator
int $count

Return Value

Builder|QueriesRelationships

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

Add a relationship count / exists condition to the query.

Parameters

string $relation
string $boolean
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orDoesntHave(string $relation)

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

Parameters

string $relation

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships whereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)

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

Parameters

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

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

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

Parameters

string $relation
Closure $callback

Return Value

Builder|QueriesRelationships

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

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

Parameters

string $relation
Closure $callback

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships hasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

Get the BelongsTo relationship for a single polymorphic type.

Parameters

MorphTo $relation
string $type

Return Value

BelongsTo

Builder|QueriesRelationships orHasMorph(MorphTo|string $relation, string|array $types, string $operator = '>=', 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
int $count

Return Value

Builder|QueriesRelationships

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

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

Builder|QueriesRelationships

Builder|QueriesRelationships whereHasMorph(MorphTo|string $relation, string|array $types, Closure $callback = null, string $operator = '>=', int $count = 1)

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

Parameters

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

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereHasMorph(MorphTo|string $relation, string|array $types, Closure $callback = null, string $operator = '>=', int $count = 1)

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

Add a basic where clause to a relationship query.

Parameters

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

Return Value

Builder|QueriesRelationships

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

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

Parameters

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

Return Value

Builder|QueriesRelationships

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

Builder|QueriesRelationships

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

Builder|QueriesRelationships

Builder|QueriesRelationships whereMorphedTo(MorphTo|string $relation, Model|string $model, $boolean = 'and')

Add a morph-to relationship condition to the query.

Parameters

MorphTo|string $relation
Model|string $model
$boolean

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships orWhereMorphedTo(MorphTo|string $relation, Model|string $model)

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

Parameters

MorphTo|string $relation
Model|string $model

Return Value

Builder|QueriesRelationships

$this whereBelongsTo(Model $related, $relationshipName = null, string $boolean = 'and')

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

Parameters

Model $related
$relationshipName
string $boolean

Return Value

$this

Exceptions

RuntimeException

$this orWhereBelongsTo(Model $related, $relationshipName = null)

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

Parameters

Model $related
$relationshipName

Return Value

$this

Exceptions

RuntimeException

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

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

Parameters

mixed $relations
string $column
string $function

Return Value

$this

$this withCount(mixed $relations)

Add subselect queries to count the relations.

Parameters

mixed $relations

Return Value

$this

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

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

Parameters

string|array $relation
string $column

Return Value

$this

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

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

Parameters

string|array $relation
string $column

Return Value

$this

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

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

Parameters

string|array $relation
string $column

Return Value

$this

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

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

Parameters

string|array $relation
string $column

Return Value

$this

$this withExists(string|array $relation)

Add subselect queries to include the existence of related models.

Parameters

string|array $relation

Return Value

$this

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

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

Parameters

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

Return Value

Builder|QueriesRelationships

Builder|QueriesRelationships mergeConstraintsFrom(Builder $from)

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

Parameters

Builder $from

Return Value

Builder|QueriesRelationships

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

Add a sub-query count clause to this query.

Parameters

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

Return Value

$this

protected Relation getRelationWithoutConstraints(string $relation)

Get the "has relation" base query instance.

Parameters

string $relation

Return Value

Relation

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

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

Parameters

string $operator
int $count

Return Value

bool

void __construct(Builder $query)

Create a new Eloquent query builder instance.

Parameters

Builder $query

Return Value

void

Model|Builder make(array $attributes = [])

Create and return an un-saved model instance.

Parameters

array $attributes

Return Value

Model|Builder

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

Register a new global scope.

Parameters

string $identifier
Scope|Closure $scope

Return Value

$this

$this withoutGlobalScope(Scope|string $scope)

Remove a registered global scope.

Parameters

Scope|string $scope

Return Value

$this

$this withoutGlobalScopes(array $scopes = null)

Remove all or passed registered global scopes.

Parameters

array $scopes

Return Value

$this

array removedScopes()

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

Return Value

array

$this whereKey(mixed $id)

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

Parameters

mixed $id

Return Value

$this

$this whereKeyNot(mixed $id)

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

Parameters

mixed $id

Return Value

$this

Model|Builder|null firstWhere(Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic where clause to the query, and return the first result.

Parameters

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

Return Value

Model|Builder|null

Collection hydrate(array $items)

Create a collection of models from plain arrays.

Parameters

array $items

Return Value

Collection

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

Create a collection of models from a raw query.

Parameters

string $query
array $bindings

Return Value

Collection

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

Find multiple models by their primary keys.

Parameters

Arrayable|array $ids
array $columns

Return Value

Collection

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

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

Parameters

mixed $id
array $columns

Return Value

Model|Collection|Builder|Builder[]

Exceptions

ModelNotFoundException

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

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

Parameters

mixed $id
array $columns

Return Value

Model|Builder

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

Get the first record matching the attributes or instantiate it.

Parameters

array $attributes
array $values

Return Value

Model|Builder

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

Get the first record matching the attributes or create it.

Parameters

array $attributes
array $values

Return Value

Model|Builder

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

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

Parameters

array $attributes
array $values

Return Value

Model|Builder

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

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

Parameters

array $columns

Return Value

Model|Builder

Exceptions

ModelNotFoundException

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

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

Parameters

Closure|array $columns
Closure $callback

Return Value

Model|Builder|mixed

mixed valueOrFail(string|Expression $column)

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

Parameters

string|Expression $column

Return Value

mixed

Exceptions

ModelNotFoundException

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

Get the hydrated models without eager loading.

Parameters

array|string $columns

Return Value

Model[]|Builder[]

array eagerLoadRelations(array $models)

Eager load the relationships for the models.

Parameters

array $models

Return Value

array

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

Relation getRelation(string $name)

Get the relation instance for the given relation name.

Parameters

string $name

Return Value

Relation

protected array relationsNestedUnder(string $relation)

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

Parameters

string $relation

Return Value

array

protected bool isNestedUnder(string $relation, string $name)

Determine if the relationship is nested.

Parameters

string $relation
string $name

Return Value

bool

protected void enforceOrderBy()

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

Return Value

void

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

Paginate the given query.

Parameters

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

Return Value

LengthAwarePaginator

Exceptions

InvalidArgumentException

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

Paginate the given query into a simple paginator.

Parameters

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

Return Value

Paginator

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

Paginate the given query into a cursor paginator.

Parameters

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

Return Value

CursorPaginator

protected Collection ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

Parameters

bool $shouldReverse

Return Value

Collection

Model|$this create(array $attributes = [])

Save a new model and return the instance.

Parameters

array $attributes

Return Value

Model|$this

Model|$this forceCreate(array $attributes)

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

Parameters

array $attributes

Return Value

Model|$this

protected array addUpdatedAtColumn(array $values)

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

Parameters

array $values

Return Value

array

protected array addTimestampsToUpsertValues(array $values)

Add timestamps to the inserted values.

Parameters

array $values

Return Value

array

protected array addUpdatedAtToUpsertColumns(array $update)

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

Parameters

array $update

Return Value

array

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

void onDelete(Closure $callback)

Register a replacement for the default delete function.

Parameters

Closure $callback

Return Value

void

bool hasNamedScope(string $scope)

Determine if the given model has a scope.

Parameters

string $scope

Return Value

bool

Builder|mixed scopes(array|string $scopes)

Call the given local model scopes.

Parameters

array|string $scopes

Return Value

Builder|mixed

Builder applyScopes()

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

Return Value

Builder

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

Apply the given scope on the current builder instance.

Parameters

callable $scope
array $parameters

Return Value

mixed

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

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

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

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

Create a where array with nested where conditions.

Parameters

array $whereSlice
string $boolean

Return Value

array

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

Set the relationships that should be eager loaded.

Parameters

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

Return Value

$this

$this without(mixed $relations)

Prevent the specified relations from being eager loaded.

Parameters

mixed $relations

Return Value

$this

$this withOnly(mixed $relations)

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

Parameters

mixed $relations

Return Value

$this

Model|Builder newModelInstance(array $attributes = [])

Create a new instance of the model being queried.

Parameters

array $attributes

Return Value

Model|Builder

protected array parseWithRelations(array $relations)

Parse a list of relations into individuals.

Parameters

array $relations

Return Value

array

protected array createSelectWithConstraint(string $name)

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

Parameters

string $name

Return Value

array

protected array addNestedWiths(string $name, array $results)

Parse the nested relationships in a relation.

Parameters

string $name
array $results

Return Value

array

$this withCasts(array $casts)

Apply query-time casts to the model instance.

Parameters

array $casts

Return Value

$this

Builder getQuery()

Get the underlying query builder instance.

Return Value

Builder

$this setQuery(Builder $query)

Set the underlying query builder instance.

Parameters

Builder $query

Return Value

$this

array getEagerLoads()

Get the relationships being eagerly loaded.

Return Value

array

$this setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

Parameters

array $eagerLoad

Return Value

$this

protected string defaultKeyName()

Get the default key name of the table.

Return Value

string

Model|Builder getModel()

Get the model instance being queried.

Return Value

Model|Builder

$this setModel(Model $model)

Set a model instance for the model being queried.

Parameters

Model $model

Return Value

$this

string qualifyColumn(string|Expression $column)

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

Parameters

string|Expression $column

Return Value

string

array qualifyColumns(array|Expression $columns)

Qualify the given columns with the model's table.

Parameters

array|Expression $columns

Return Value

array

Closure getMacro(string $name)

Get the given macro by name.

Parameters

string $name

Return Value

Closure

bool hasMacro(string $name)

Checks if a macro is registered.

Parameters

string $name

Return Value

bool

static Closure getGlobalMacro(string $name)

Get the given global macro by name.

Parameters

string $name

Return Value

Closure

static bool hasGlobalMacro(string $name)

Checks if a global macro is registered.

Parameters

string $name

Return Value

bool

mixed __get(string $key)

Dynamically access builder proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

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

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static protected void registerMixin(string $mixin, bool $replace)

Register the given mixin with the builder.

Parameters

string $mixin
bool $replace

Return Value

void

void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void