class JoinClause extends Builder (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
ConnectionInterface $connection

The database connection instance.

from  Builder
Grammar $grammar

The database query grammar instance.

from  Builder
Processor $processor

The database query post processor instance.

from  Builder
array $bindings

The current query value bindings.

from  Builder
array $aggregate

An aggregate function and column to be run.

from  Builder
array|null $columns

The columns that should be returned.

from  Builder
bool|array $distinct

Indicates if the query returns distinct results.

from  Builder
Expression|string $from

The table which the query is targeting.

from  Builder
IndexHint $indexHint

The index hint for the query.

from  Builder
array $joins

The table joins for the query.

from  Builder
array $wheres

The where constraints for the query.

from  Builder
array $groups

The groupings for the query.

from  Builder
array $havings

The having constraints for the query.

from  Builder
array|null $orders

The orderings for the query.

from  Builder
int|null $limit

The maximum number of records to return.

from  Builder
array $groupLimit

The maximum number of records to return per group.

from  Builder
int|null $offset

The number of records to skip.

from  Builder
array $unions

The query union statements.

from  Builder
int|null $unionLimit

The maximum number of union records to return.

from  Builder
int|null $unionOffset

The number of union records to skip.

from  Builder
array|null $unionOrders

The orderings for the union query.

from  Builder
string|bool $lock

Indicates whether row locking is being used.

from  Builder
array $beforeQueryCallbacks

The callbacks that should be invoked before the query is executed.

from  Builder
protected array $afterQueryCallbacks

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

from  Builder
string[] $operators

All of the available clause operators.

from  Builder
string[] $bitwiseOperators

All of the available bitwise operators.

from  Builder
bool $useWritePdo

Whether to use write pdo for the select.

from  Builder
string $type

The type of join being performed.

string $table

The table the join clause is joining to.

protected ConnectionInterface $parentConnection

The connection of the parent query builder.

protected Grammar $parentGrammar

The grammar of the parent query builder.

protected Processor $parentProcessor

The processor of the parent query builder.

protected string $parentClass

The class name of the parent query builder.

Methods

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

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

$this|TUnlessReturnType
unless($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.

TReturn>
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, 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, bool $descending = false)

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

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

Execute the query and get the first result.

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

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

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

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

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

Paginate the given query using a cursor paginator.

string
getOriginalColumnNameForCursorPagination($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($callback)

Pass the query to a given callback.

explain()

Explains the query.

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.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

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

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

void
__construct(Builder $parentQuery, string $type, string $table)

Create a new join clause instance.

$this
select(array|mixed $columns = ['*'])

Set the columns to be selected.

from  Builder
$this
selectSub($query, string $as)

Add a subselect expression to the query.

from  Builder
$this
selectRaw(string $expression, array $bindings = [])

Add a new "raw" select expression to the query.

from  Builder
$this
fromSub($query, string $as)

Makes "from" fetch from a subquery.

from  Builder
$this
fromRaw(string $expression, mixed $bindings = [])

Add a raw from clause to the query.

from  Builder
array
createSub($query)

Creates a subquery and parse it.

from  Builder
array
parseSub(mixed $query)

Parse the subquery into SQL and bindings.

from  Builder
mixed
prependDatabaseNameIfCrossDatabaseQuery(mixed $query)

Prepend the database name if the given query is on another database.

from  Builder
$this
addSelect(array|mixed $column)

Add a new select column to the query.

from  Builder
$this
distinct()

Force the query to only return distinct results.

from  Builder
$this
from($table, string|null $as = null)

Set the table which the query is targeting.

from  Builder
$this
useIndex(string $index)

Add an index hint to suggest a query index.

from  Builder
$this
forceIndex(string $index)

Add an index hint to force a query index.

from  Builder
$this
ignoreIndex(string $index)

Add an index hint to ignore a query index.

from  Builder
$this
join(Expression|string $table, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $type = 'inner', bool $where = false)

Add a join clause to the query.

from  Builder
$this
joinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string $second, string $type = 'inner')

Add a "join where" clause to the query.

from  Builder
$this
joinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $type = 'inner', bool $where = false)

Add a subquery join clause to the query.

from  Builder
$this
joinLateral($query, string $as, string $type = 'inner')

Add a lateral join clause to the query.

from  Builder
$this
leftJoinLateral($query, string $as)

Add a lateral left join to the query.

from  Builder
$this
leftJoin(Expression|string $table, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a left join to the query.

from  Builder
$this
leftJoinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string|null $second)

Add a "join where" clause to the query.

from  Builder
$this
leftJoinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a subquery left join to the query.

from  Builder
$this
rightJoin(Expression|string $table, Closure|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a right join to the query.

from  Builder
$this
rightJoinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string $second)

Add a "right join where" clause to the query.

from  Builder
$this
rightJoinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a subquery right join to the query.

from  Builder
$this
crossJoin(Expression|string $table, Closure|Expression|string|null $first = null, string|null $operator = null, Expression|string|null $second = null)

Add a "cross join" clause to the query.

from  Builder
$this
crossJoinSub($query, string $as)

Add a subquery cross join to the query.

from  Builder
newJoinClause(Builder $parentQuery, string $type, Expression|string $table)

Get a new join clause.

from  Builder
newJoinLateralClause(Builder $parentQuery, string $type, Expression|string $table)

Get a new join lateral clause.

from  Builder
$this
mergeWheres(array $wheres, array $bindings)

Merge an array of where clauses and bindings.

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

Add a basic where clause to the query.

from  Builder
$this
addArrayOfWheres(array $column, string $boolean, string $method = 'where')

Add an array of where clauses to the query.

from  Builder
array
prepareValueAndOperator(string $value, string $operator, bool $useDefault = false)

Prepare the value and operator for a where clause.

from  Builder
bool
invalidOperatorAndValue(string $operator, mixed $value)

Determine if the given operator and value combination is legal.

from  Builder
bool
invalidOperator(string $operator)

Determine if the given operator is supported.

from  Builder
bool
isBitwiseOperator(string $operator)

Determine if the operator is a bitwise operator.

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

Add an "or where" clause to the query.

from  Builder
$this
whereNot(Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic "where not" clause to the query.

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

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

from  Builder
$this
whereColumn(Expression|string|array $first, string|null $operator = null, string|null $second = null, string|null $boolean = 'and')

Add a "where" clause comparing two columns to the query.

from  Builder
$this
orWhereColumn(Expression|string|array $first, string|null $operator = null, string|null $second = null)

Add an "or where" clause comparing two columns to the query.

from  Builder
$this
whereRaw(string $sql, mixed $bindings = [], string $boolean = 'and')

Add a raw where clause to the query.

from  Builder
$this
orWhereRaw(string $sql, mixed $bindings = [])

Add a raw or where clause to the query.

from  Builder
$this
whereLike(Expression|string $column, string $value, bool $caseSensitive = false, string $boolean = 'and', bool $not = false)

Add a "where like" clause to the query.

from  Builder
$this
orWhereLike(Expression|string $column, string $value, bool $caseSensitive = false)

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

from  Builder
$this
whereNotLike(Expression|string $column, string $value, bool $caseSensitive = false, string $boolean = 'and')

Add a "where not like" clause to the query.

from  Builder
$this
orWhereNotLike(Expression|string $column, string $value, bool $caseSensitive = false)

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

from  Builder
$this
whereIn(Expression|string $column, mixed $values, string $boolean = 'and', bool $not = false)

Add a "where in" clause to the query.

from  Builder
$this
orWhereIn(Expression|string $column, mixed $values)

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

from  Builder
$this
whereNotIn(Expression|string $column, mixed $values, string $boolean = 'and')

Add a "where not in" clause to the query.

from  Builder
$this
orWhereNotIn(Expression|string $column, mixed $values)

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

from  Builder
$this
whereIntegerInRaw(string $column, Arrayable|array $values, string $boolean = 'and', bool $not = false)

Add a "where in raw" clause for integer values to the query.

from  Builder
$this
orWhereIntegerInRaw(string $column, Arrayable|array $values)

Add an "or where in raw" clause for integer values to the query.

from  Builder
$this
whereIntegerNotInRaw(string $column, Arrayable|array $values, string $boolean = 'and')

Add a "where not in raw" clause for integer values to the query.

from  Builder
$this
orWhereIntegerNotInRaw(string $column, Arrayable|array $values)

Add an "or where not in raw" clause for integer values to the query.

from  Builder
$this
whereNull(string|array|Expression $columns, string $boolean = 'and', bool $not = false)

Add a "where null" clause to the query.

from  Builder
$this
orWhereNull(string|array|Expression $column)

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

from  Builder
$this
whereNotNull(string|array|Expression $columns, string $boolean = 'and')

Add a "where not null" clause to the query.

from  Builder
$this
whereBetween(Expression|string $column, iterable $values, string $boolean = 'and', bool $not = false)

Add a where between statement to the query.

from  Builder
$this
whereBetweenColumns(Expression|string $column, array $values, string $boolean = 'and', bool $not = false)

Add a where between statement using columns to the query.

from  Builder
$this
orWhereBetween(Expression|string $column, iterable $values)

Add an or where between statement to the query.

from  Builder
$this
orWhereBetweenColumns(Expression|string $column, array $values)

Add an or where between statement using columns to the query.

from  Builder
$this
whereNotBetween(Expression|string $column, iterable $values, string $boolean = 'and')

Add a where not between statement to the query.

from  Builder
$this
whereNotBetweenColumns(Expression|string $column, array $values, string $boolean = 'and')

Add a where not between statement using columns to the query.

from  Builder
$this
orWhereNotBetween(Expression|string $column, iterable $values)

Add an or where not between statement to the query.

from  Builder
$this
orWhereNotBetweenColumns(Expression|string $column, array $values)

Add an or where not between statement using columns to the query.

from  Builder
$this
orWhereNotNull(Expression|string $column)

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

from  Builder
$this
whereDate(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null, string $boolean = 'and')

Add a "where date" statement to the query.

from  Builder
$this
orWhereDate(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null)

Add an "or where date" statement to the query.

from  Builder
$this
whereTime(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null, string $boolean = 'and')

Add a "where time" statement to the query.

from  Builder
$this
orWhereTime(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null)

Add an "or where time" statement to the query.

from  Builder
$this
whereDay(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where day" statement to the query.

from  Builder
$this
orWhereDay(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where day" statement to the query.

from  Builder
$this
whereMonth(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where month" statement to the query.

from  Builder
$this
orWhereMonth(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where month" statement to the query.

from  Builder
$this
whereYear(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where year" statement to the query.

from  Builder
$this
orWhereYear(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where year" statement to the query.

from  Builder
$this
addDateBasedWhere(string $type, Expression|string $column, string $operator, mixed $value, string $boolean = 'and')

Add a date based (year, month, day, time) statement to the query.

from  Builder
$this
whereNested(Closure $callback, string $boolean = 'and')

Add a nested where statement to the query.

from  Builder
forNestedWhere()

Create a new query instance for nested where condition.

from  Builder
$this
addNestedWhereQuery(Builder $query, string $boolean = 'and')

Add another query builder as a nested where to the query builder.

from  Builder
$this
whereSub(Expression|string $column, string $operator, $callback, string $boolean)

Add a full sub-select to the query.

from  Builder
$this
whereExists($callback, string $boolean = 'and', bool $not = false)

Add an exists clause to the query.

from  Builder
$this
orWhereExists($callback, bool $not = false)

Add an or exists clause to the query.

from  Builder
$this
whereNotExists($callback, string $boolean = 'and')

Add a where not exists clause to the query.

from  Builder
$this
orWhereNotExists($callback)

Add a where not exists clause to the query.

from  Builder
$this
addWhereExistsQuery(Builder $query, string $boolean = 'and', bool $not = false)

Add an exists clause to the query.

from  Builder
$this
whereRowValues(array $columns, string $operator, array $values, string $boolean = 'and')

Adds a where condition using row values.

from  Builder
$this
orWhereRowValues(array $columns, string $operator, array $values)

Adds an or where condition using row values.

from  Builder
$this
whereJsonContains(string $column, mixed $value, string $boolean = 'and', bool $not = false)

Add a "where JSON contains" clause to the query.

from  Builder
$this
orWhereJsonContains(string $column, mixed $value)

Add an "or where JSON contains" clause to the query.

from  Builder
$this
whereJsonDoesntContain(string $column, mixed $value, string $boolean = 'and')

Add a "where JSON not contains" clause to the query.

from  Builder
$this
orWhereJsonDoesntContain(string $column, mixed $value)

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

from  Builder
$this
whereJsonOverlaps(string $column, mixed $value, string $boolean = 'and', bool $not = false)

Add a "where JSON overlaps" clause to the query.

from  Builder
$this
orWhereJsonOverlaps(string $column, mixed $value)

Add an "or where JSON overlaps" clause to the query.

from  Builder
$this
whereJsonDoesntOverlap(string $column, mixed $value, string $boolean = 'and')

Add a "where JSON not overlap" clause to the query.

from  Builder
$this
orWhereJsonDoesntOverlap(string $column, mixed $value)

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

from  Builder
$this
whereJsonContainsKey(string $column, string $boolean = 'and', bool $not = false)

Add a clause that determines if a JSON path exists to the query.

from  Builder
$this
orWhereJsonContainsKey(string $column)

Add an "or" clause that determines if a JSON path exists to the query.

from  Builder
$this
whereJsonDoesntContainKey(string $column, string $boolean = 'and')

Add a clause that determines if a JSON path does not exist to the query.

from  Builder
$this
orWhereJsonDoesntContainKey(string $column)

Add an "or" clause that determines if a JSON path does not exist to the query.

from  Builder
$this
whereJsonLength(string $column, mixed $operator, mixed $value = null, string $boolean = 'and')

Add a "where JSON length" clause to the query.

from  Builder
$this
orWhereJsonLength(string $column, mixed $operator, mixed $value = null)

Add an "or where JSON length" clause to the query.

from  Builder
$this
dynamicWhere(string $method, array $parameters)

Handles dynamic "where" clauses to the query.

from  Builder
void
addDynamic(string $segment, string $connector, array $parameters, int $index)

Add a single dynamic where clause statement to the query.

from  Builder
$this
whereFullText(string|string[] $columns, string $value, array $options = [], string $boolean = 'and')

Add a "where fulltext" clause to the query.

from  Builder
$this
orWhereFullText(string|string[] $columns, string $value, array $options = [])

Add a "or where fulltext" clause to the query.

from  Builder
$this
whereAll(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where" clause to the query for multiple columns with "and" conditions between them.

from  Builder
$this
orWhereAll(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query for multiple columns with "and" conditions between them.

from  Builder
$this
whereAny(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where" clause to the query for multiple columns with "or" conditions between them.

from  Builder
$this
orWhereAny(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query for multiple columns with "or" conditions between them.

from  Builder
$this
whereNone(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where not" clause to the query for multiple columns where none of the conditions should be true.

from  Builder
$this
orWhereNone(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where not" clause to the query for multiple columns where none of the conditions should be true.

from  Builder
$this
groupBy(array|Expression|string ...$groups)

Add a "group by" clause to the query.

from  Builder
$this
groupByRaw(string $sql, array $bindings = [])

Add a raw groupBy clause to the query.

from  Builder
$this
having(Expression|Closure|string $column, string|int|float|null $operator = null, string|int|float|null $value = null, string $boolean = 'and')

Add a "having" clause to the query.

from  Builder
$this
orHaving(Expression|Closure|string $column, string|int|float|null $operator = null, string|int|float|null $value = null)

Add an "or having" clause to the query.

from  Builder
$this
havingNested(Closure $callback, string $boolean = 'and')

Add a nested having statement to the query.

from  Builder
$this
addNestedHavingQuery(Builder $query, string $boolean = 'and')

Add another query builder as a nested having to the query builder.

from  Builder
$this
havingNull(string|array $columns, string $boolean = 'and', bool $not = false)

Add a "having null" clause to the query.

from  Builder
$this
orHavingNull(string $column)

Add an "or having null" clause to the query.

from  Builder
$this
havingNotNull(string|array $columns, string $boolean = 'and')

Add a "having not null" clause to the query.

from  Builder
$this
orHavingNotNull(string $column)

Add an "or having not null" clause to the query.

from  Builder
$this
havingBetween(string $column, iterable $values, string $boolean = 'and', bool $not = false)

Add a "having between " clause to the query.

from  Builder
$this
havingRaw(string $sql, array $bindings = [], string $boolean = 'and')

Add a raw having clause to the query.

from  Builder
$this
orHavingRaw(string $sql, array $bindings = [])

Add a raw or having clause to the query.

from  Builder
$this
orderBy($column, string $direction = 'asc')

Add an "order by" clause to the query.

from  Builder
$this
orderByDesc($column)

Add a descending "order by" clause to the query.

from  Builder
$this
latest(Closure|Builder|Expression|string $column = 'created_at')

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

from  Builder
$this
oldest(Closure|Builder|Expression|string $column = 'created_at')

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

from  Builder
$this
inRandomOrder(string|int $seed = '')

Put the query's results in random order.

from  Builder
$this
orderByRaw(string $sql, array $bindings = [])

Add a raw "order by" clause to the query.

from  Builder
$this
skip(int $value)

Alias to set the "offset" value of the query.

from  Builder
$this
offset(int $value)

Set the "offset" value of the query.

from  Builder
$this
take(int $value)

Alias to set the "limit" value of the query.

from  Builder
$this
limit(int $value)

Set the "limit" value of the query.

from  Builder
$this
groupLimit(int $value, string $column)

Add a "group limit" clause to the query.

from  Builder
$this
forPage(int $page, int $perPage = 15)

Set the limit and offset for a given page.

from  Builder
$this
forPageBeforeId(int $perPage = 15, int|null $lastId = 0, string $column = 'id')

Constrain the query to the previous "page" of results before a given ID.

from  Builder
$this
forPageAfterId(int $perPage = 15, int|null $lastId = 0, string $column = 'id')

Constrain the query to the next "page" of results after a given ID.

from  Builder
$this
reorder(Closure|Builder|Expression|string|null $column = null, string $direction = 'asc')

Remove all existing orders and optionally add a new order.

from  Builder
array
removeExistingOrdersFor(string $column)

Get an array with all orders with a given column removed.

from  Builder
$this
union($query, bool $all = false)

Add a union statement to the query.

from  Builder
$this
unionAll($query)

Add a union all statement to the query.

from  Builder
$this
lock(string|bool $value = true)

Lock the selected rows in the table.

from  Builder
$this
lockForUpdate()

Lock the selected rows in the table for updating.

from  Builder
$this
sharedLock()

Share lock the selected rows in the table.

from  Builder
$this
beforeQuery(callable $callback)

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

from  Builder
void
applyBeforeQueryCallbacks()

Invoke the "before query" modification callbacks.

from  Builder
$this
afterQuery(Closure $callback)

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

from  Builder
mixed
applyAfterQueryCallbacks(mixed $result)

Invoke the "after query" modification callbacks.

from  Builder
string
toSql()

Get the SQL representation of the query.

from  Builder
string
toRawSql()

Get the raw SQL representation of the query with embedded bindings.

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

Execute a query for a single record by ID.

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

No description

from  Builder
mixed
value(string $column)

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

from  Builder
mixed
rawValue(string $expression, array $bindings = [])

Get a single expression value from the first result of a query.

from  Builder
mixed
soleValue(string $column)

Get a single column's value from the first result of a query if it's the sole matching record.

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

Execute the query as a "select" statement.

from  Builder
array
runSelect()

Run the query as a "select" statement against the connection.

from  Builder
withoutGroupLimitKeys(Collection $items)

Remove the group limit keys from the results in the collection.

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

Paginate the given query into a simple paginator.

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

Get a paginator only supporting simple next and previous links.

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

Get a paginator only supporting simple next and previous links.

from  Builder
ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

from  Builder
int
getCountForPagination(array $columns = ['*'])

Get the count of the total records for the paginator.

from  Builder
array
runPaginationCountQuery(array $columns = ['*'])

Run a pagination count query.

from  Builder
cloneForPaginationCount()

Clone the existing query instance for usage in a pagination subquery.

from  Builder
array
withoutSelectAliases(array $columns)

Remove the column aliases since they will break count queries.

from  Builder
stdClass>
cursor()

Get a lazy collection for the given query.

from  Builder
void
enforceOrderBy()

Throw an exception if the query doesn't have an orderBy clause.

from  Builder
Collection<array-key,mixed>
pluck(Expression|string $column, string|null $key = null)

Get a collection instance containing the values of a given column.

from  Builder
string|null
stripTableForPluck(string $column)

Strip off the table name or alias from a column identifier.

from  Builder
pluckFromObjectColumn(array $queryResult, string $column, string $key)

Retrieve column values from rows represented as objects.

from  Builder
pluckFromArrayColumn(array $queryResult, string $column, string $key)

Retrieve column values from rows represented as arrays.

from  Builder
string
implode(string $column, string $glue = '')

Concatenate values of a given column as a string.

from  Builder
bool
exists()

Determine if any rows exist for the current query.

from  Builder
bool
doesntExist()

Determine if no rows exist for the current query.

from  Builder
mixed
existsOr(Closure $callback)

Execute the given callback if no rows exist for the current query.

from  Builder
mixed
doesntExistOr(Closure $callback)

Execute the given callback if rows exist for the current query.

from  Builder
int
count(Expression|string $columns = '*')

Retrieve the "count" result of the query.

from  Builder
mixed
min(Expression|string $column)

Retrieve the minimum value of a given column.

from  Builder
mixed
max(Expression|string $column)

Retrieve the maximum value of a given column.

from  Builder
mixed
sum(Expression|string $column)

Retrieve the sum of the values of a given column.

from  Builder
mixed
avg(Expression|string $column)

Retrieve the average of the values of a given column.

from  Builder
mixed
average(Expression|string $column)

Alias for the "avg" method.

from  Builder
mixed
aggregate(string $function, array $columns = ['*'])

Execute an aggregate function on the database.

from  Builder
float|int
numericAggregate(string $function, array $columns = ['*'])

Execute a numeric aggregate function on the database.

from  Builder
$this
setAggregate(string $function, array $columns)

Set the aggregate property without running the query.

from  Builder
mixed
onceWithColumns(array $columns, callable $callback)

Execute the given callback while selecting the given columns.

from  Builder
bool
insert(array $values)

Insert new records into the database.

from  Builder
int
insertOrIgnore(array $values)

Insert new records into the database while ignoring errors.

from  Builder
int
insertGetId(array $values, string|null $sequence = null)

Insert a new record and get the value of the primary key.

from  Builder
int
insertUsing(array $columns, $query)

Insert new records into the table using a subquery.

from  Builder
int
insertOrIgnoreUsing(array $columns, $query)

Insert new records into the table using a subquery while ignoring errors.

from  Builder
int
update(array $values)

Update records in the database.

from  Builder
int
updateFrom(array $values)

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

from  Builder
bool
updateOrInsert(array $attributes, array|callable $values = [])

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

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

Insert new records or update the existing ones.

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

Increment a column's value by a given amount.

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

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

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

Decrement a column's value by a given amount.

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

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

from  Builder
int
delete(mixed $id = null)

Delete records from the database.

from  Builder
void
truncate()

Run a truncate statement on the table.

from  Builder
newQuery()

Get a new instance of the join clause builder.

forSubQuery()

Create a new query instance for sub-query.

array
getColumns()

Get all of the query builder's columns in a text-only array with all expressions evaluated.

from  Builder
raw(mixed $value)

Create a raw database expression.

from  Builder
getUnionBuilders()

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

from  Builder
mixed
getLimit()

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

from  Builder
mixed
getOffset()

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

from  Builder
array
getBindings()

Get the current query value bindings in a flattened array.

from  Builder
array
getRawBindings()

Get the raw array of bindings.

from  Builder
$this
setBindings(array $bindings, string $type = 'where')

Set the bindings on the query builder.

from  Builder
$this
addBinding(mixed $value, string $type = 'where')

Add a binding to the query.

from  Builder
mixed
castBinding(mixed $value)

Cast the given binding value.

from  Builder
$this
mergeBindings(Builder $query)

Merge an array of bindings into our bindings.

from  Builder
array
cleanBindings(array $bindings)

Remove all of the expressions from a list of bindings.

from  Builder
mixed
flattenValue(mixed $value)

Get a scalar type value from an unknown type of input.

from  Builder
string
defaultKeyName()

Get the default key name of the table.

from  Builder
getConnection()

Get the database connection instance.

from  Builder
getProcessor()

Get the database query processor instance.

from  Builder
getGrammar()

Get the query grammar instance.

from  Builder
$this
useWritePdo()

Use the "write" PDO connection when executing the query.

from  Builder
bool
isQueryable(mixed $value)

Determine if the value is a query builder instance or a Closure.

from  Builder
clone()

Clone the query.

from  Builder
cloneWithout(array $properties)

Clone the query without the given properties.

from  Builder
cloneWithoutBindings(array $except)

Clone the query without the given bindings.

from  Builder
$this
dump(mixed ...$args)

Dump the current SQL and bindings.

from  Builder
$this
dumpRawSql()

Dump the raw current SQL with embedded bindings.

from  Builder
never
dd()

Die and dump the current SQL and bindings.

from  Builder
never
ddRawSql()

Die and dump the current SQL with embedded bindings.

from  Builder
$this
on(Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $boolean = 'and')

Add an "on" clause to the join.

orOn(Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add an "or on" clause to the join.

newParentQuery()

Create a new parent query instance.

Details

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

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

Parameters

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

Return Value

$this|TWhenReturnType

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

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

Parameters

$value
callable|null $callback
callable|null $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

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

Run a map over each item while chunking.

Parameters

callable $callback
int $count

Return Value

TReturn>

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

bool orderedChunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null, 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
bool $descending

Return Value

bool

Exceptions

RuntimeException

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

Exceptions

InvalidArgumentException

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

Exceptions

InvalidArgumentException

protected LazyCollection orderedLazyById(int $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

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

Return Value

LazyCollection

Exceptions

InvalidArgumentException

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

Execute the query and get the first result.

Parameters

array|string $columns

Return Value

TValue|null

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

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

Parameters

array|string $columns
string|null $message

Return Value

TValue

Exceptions

RecordNotFoundException

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

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

Parameters

array|string $columns

Return Value

TValue

Exceptions

RecordsNotFoundException
MultipleRecordsFoundException

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

protected string getOriginalColumnNameForCursorPagination($builder, string $parameter)

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

Parameters

$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($callback)

Pass the query to a given callback.

Parameters

$callback

Return Value

$this

Collection explain()

Explains the query.

Return Value

Collection

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

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

never

Exceptions

BadMethodCallException

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(Builder $parentQuery, string $type, string $table)

Create a new join clause instance.

Parameters

Builder $parentQuery
string $type
string $table

Return Value

void

$this select(array|mixed $columns = ['*'])

Set the columns to be selected.

Parameters

array|mixed $columns

Return Value

$this

$this selectSub($query, string $as)

Add a subselect expression to the query.

Parameters

$query
string $as

Return Value

$this

Exceptions

InvalidArgumentException

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

Add a new "raw" select expression to the query.

Parameters

string $expression
array $bindings

Return Value

$this

$this fromSub($query, string $as)

Makes "from" fetch from a subquery.

Parameters

$query
string $as

Return Value

$this

Exceptions

InvalidArgumentException

$this fromRaw(string $expression, mixed $bindings = [])

Add a raw from clause to the query.

Parameters

string $expression
mixed $bindings

Return Value

$this

protected array createSub($query)

Creates a subquery and parse it.

Parameters

$query

Return Value

array

protected array parseSub(mixed $query)

Parse the subquery into SQL and bindings.

Parameters

mixed $query

Return Value

array

Exceptions

InvalidArgumentException

protected mixed prependDatabaseNameIfCrossDatabaseQuery(mixed $query)

Prepend the database name if the given query is on another database.

Parameters

mixed $query

Return Value

mixed

$this addSelect(array|mixed $column)

Add a new select column to the query.

Parameters

array|mixed $column

Return Value

$this

$this distinct()

Force the query to only return distinct results.

Return Value

$this

$this from($table, string|null $as = null)

Set the table which the query is targeting.

Parameters

$table
string|null $as

Return Value

$this

$this useIndex(string $index)

Add an index hint to suggest a query index.

Parameters

string $index

Return Value

$this

$this forceIndex(string $index)

Add an index hint to force a query index.

Parameters

string $index

Return Value

$this

$this ignoreIndex(string $index)

Add an index hint to ignore a query index.

Parameters

string $index

Return Value

$this

$this join(Expression|string $table, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $type = 'inner', bool $where = false)

Add a join clause to the query.

Parameters

Expression|string $table
Closure|Expression|string $first
string|null $operator
Expression|string|null $second
string $type
bool $where

Return Value

$this

$this joinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string $second, string $type = 'inner')

Add a "join where" clause to the query.

Parameters

Expression|string $table
Closure|Expression|string $first
string $operator
Expression|string $second
string $type

Return Value

$this

$this joinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $type = 'inner', bool $where = false)

Add a subquery join clause to the query.

Parameters

$query
string $as
Closure|Expression|string $first
string|null $operator
Expression|string|null $second
string $type
bool $where

Return Value

$this

Exceptions

InvalidArgumentException

$this joinLateral($query, string $as, string $type = 'inner')

Add a lateral join clause to the query.

Parameters

$query
string $as
string $type

Return Value

$this

$this leftJoinLateral($query, string $as)

Add a lateral left join to the query.

Parameters

$query
string $as

Return Value

$this

$this leftJoin(Expression|string $table, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a left join to the query.

Parameters

Expression|string $table
Closure|Expression|string $first
string|null $operator
Expression|string|null $second

Return Value

$this

$this leftJoinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string|null $second)

Add a "join where" clause to the query.

Parameters

Expression|string $table
Closure|Expression|string $first
string $operator
Expression|string|null $second

Return Value

$this

$this leftJoinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a subquery left join to the query.

Parameters

$query
string $as
Closure|Expression|string $first
string|null $operator
Expression|string|null $second

Return Value

$this

$this rightJoin(Expression|string $table, Closure|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a right join to the query.

Parameters

Expression|string $table
Closure|string $first
string|null $operator
Expression|string|null $second

Return Value

$this

$this rightJoinWhere(Expression|string $table, Closure|Expression|string $first, string $operator, Expression|string $second)

Add a "right join where" clause to the query.

Parameters

Expression|string $table
Closure|Expression|string $first
string $operator
Expression|string $second

Return Value

$this

$this rightJoinSub($query, string $as, Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add a subquery right join to the query.

Parameters

$query
string $as
Closure|Expression|string $first
string|null $operator
Expression|string|null $second

Return Value

$this

$this crossJoin(Expression|string $table, Closure|Expression|string|null $first = null, string|null $operator = null, Expression|string|null $second = null)

Add a "cross join" clause to the query.

Parameters

Expression|string $table
Closure|Expression|string|null $first
string|null $operator
Expression|string|null $second

Return Value

$this

$this crossJoinSub($query, string $as)

Add a subquery cross join to the query.

Parameters

$query
string $as

Return Value

$this

protected JoinClause newJoinClause(Builder $parentQuery, string $type, Expression|string $table)

Get a new join clause.

Parameters

Builder $parentQuery
string $type
Expression|string $table

Return Value

JoinClause

protected JoinLateralClause newJoinLateralClause(Builder $parentQuery, string $type, Expression|string $table)

Get a new join lateral clause.

Parameters

Builder $parentQuery
string $type
Expression|string $table

Return Value

JoinLateralClause

$this mergeWheres(array $wheres, array $bindings)

Merge an array of where clauses and bindings.

Parameters

array $wheres
array $bindings

Return Value

$this

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

Add a basic where clause to the query.

Parameters

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

Return Value

$this

protected $this addArrayOfWheres(array $column, string $boolean, string $method = 'where')

Add an array of where clauses to the query.

Parameters

array $column
string $boolean
string $method

Return Value

$this

array prepareValueAndOperator(string $value, string $operator, bool $useDefault = false)

Prepare the value and operator for a where clause.

Parameters

string $value
string $operator
bool $useDefault

Return Value

array

Exceptions

InvalidArgumentException

protected bool invalidOperatorAndValue(string $operator, mixed $value)

Determine if the given operator and value combination is legal.

Prevents using Null values with invalid operators.

Parameters

string $operator
mixed $value

Return Value

bool

protected bool invalidOperator(string $operator)

Determine if the given operator is supported.

Parameters

string $operator

Return Value

bool

protected bool isBitwiseOperator(string $operator)

Determine if the operator is a bitwise operator.

Parameters

string $operator

Return Value

bool

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

Add an "or where" clause to the query.

Parameters

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

Return Value

$this

$this whereNot(Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic "where not" clause to the query.

Parameters

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

Return Value

$this

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

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

Parameters

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

Return Value

$this

$this whereColumn(Expression|string|array $first, string|null $operator = null, string|null $second = null, string|null $boolean = 'and')

Add a "where" clause comparing two columns to the query.

Parameters

Expression|string|array $first
string|null $operator
string|null $second
string|null $boolean

Return Value

$this

$this orWhereColumn(Expression|string|array $first, string|null $operator = null, string|null $second = null)

Add an "or where" clause comparing two columns to the query.

Parameters

Expression|string|array $first
string|null $operator
string|null $second

Return Value

$this

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

Add a raw where clause to the query.

Parameters

string $sql
mixed $bindings
string $boolean

Return Value

$this

$this orWhereRaw(string $sql, mixed $bindings = [])

Add a raw or where clause to the query.

Parameters

string $sql
mixed $bindings

Return Value

$this

$this whereLike(Expression|string $column, string $value, bool $caseSensitive = false, string $boolean = 'and', bool $not = false)

Add a "where like" clause to the query.

Parameters

Expression|string $column
string $value
bool $caseSensitive
string $boolean
bool $not

Return Value

$this

$this orWhereLike(Expression|string $column, string $value, bool $caseSensitive = false)

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

Parameters

Expression|string $column
string $value
bool $caseSensitive

Return Value

$this

$this whereNotLike(Expression|string $column, string $value, bool $caseSensitive = false, string $boolean = 'and')

Add a "where not like" clause to the query.

Parameters

Expression|string $column
string $value
bool $caseSensitive
string $boolean

Return Value

$this

$this orWhereNotLike(Expression|string $column, string $value, bool $caseSensitive = false)

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

Parameters

Expression|string $column
string $value
bool $caseSensitive

Return Value

$this

$this whereIn(Expression|string $column, mixed $values, string $boolean = 'and', bool $not = false)

Add a "where in" clause to the query.

Parameters

Expression|string $column
mixed $values
string $boolean
bool $not

Return Value

$this

$this orWhereIn(Expression|string $column, mixed $values)

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

Parameters

Expression|string $column
mixed $values

Return Value

$this

$this whereNotIn(Expression|string $column, mixed $values, string $boolean = 'and')

Add a "where not in" clause to the query.

Parameters

Expression|string $column
mixed $values
string $boolean

Return Value

$this

$this orWhereNotIn(Expression|string $column, mixed $values)

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

Parameters

Expression|string $column
mixed $values

Return Value

$this

$this whereIntegerInRaw(string $column, Arrayable|array $values, string $boolean = 'and', bool $not = false)

Add a "where in raw" clause for integer values to the query.

Parameters

string $column
Arrayable|array $values
string $boolean
bool $not

Return Value

$this

$this orWhereIntegerInRaw(string $column, Arrayable|array $values)

Add an "or where in raw" clause for integer values to the query.

Parameters

string $column
Arrayable|array $values

Return Value

$this

$this whereIntegerNotInRaw(string $column, Arrayable|array $values, string $boolean = 'and')

Add a "where not in raw" clause for integer values to the query.

Parameters

string $column
Arrayable|array $values
string $boolean

Return Value

$this

$this orWhereIntegerNotInRaw(string $column, Arrayable|array $values)

Add an "or where not in raw" clause for integer values to the query.

Parameters

string $column
Arrayable|array $values

Return Value

$this

$this whereNull(string|array|Expression $columns, string $boolean = 'and', bool $not = false)

Add a "where null" clause to the query.

Parameters

string|array|Expression $columns
string $boolean
bool $not

Return Value

$this

$this orWhereNull(string|array|Expression $column)

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

Parameters

string|array|Expression $column

Return Value

$this

$this whereNotNull(string|array|Expression $columns, string $boolean = 'and')

Add a "where not null" clause to the query.

Parameters

string|array|Expression $columns
string $boolean

Return Value

$this

$this whereBetween(Expression|string $column, iterable $values, string $boolean = 'and', bool $not = false)

Add a where between statement to the query.

Parameters

Expression|string $column
iterable $values
string $boolean
bool $not

Return Value

$this

$this whereBetweenColumns(Expression|string $column, array $values, string $boolean = 'and', bool $not = false)

Add a where between statement using columns to the query.

Parameters

Expression|string $column
array $values
string $boolean
bool $not

Return Value

$this

$this orWhereBetween(Expression|string $column, iterable $values)

Add an or where between statement to the query.

Parameters

Expression|string $column
iterable $values

Return Value

$this

$this orWhereBetweenColumns(Expression|string $column, array $values)

Add an or where between statement using columns to the query.

Parameters

Expression|string $column
array $values

Return Value

$this

$this whereNotBetween(Expression|string $column, iterable $values, string $boolean = 'and')

Add a where not between statement to the query.

Parameters

Expression|string $column
iterable $values
string $boolean

Return Value

$this

$this whereNotBetweenColumns(Expression|string $column, array $values, string $boolean = 'and')

Add a where not between statement using columns to the query.

Parameters

Expression|string $column
array $values
string $boolean

Return Value

$this

$this orWhereNotBetween(Expression|string $column, iterable $values)

Add an or where not between statement to the query.

Parameters

Expression|string $column
iterable $values

Return Value

$this

$this orWhereNotBetweenColumns(Expression|string $column, array $values)

Add an or where not between statement using columns to the query.

Parameters

Expression|string $column
array $values

Return Value

$this

$this orWhereNotNull(Expression|string $column)

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

Parameters

Expression|string $column

Return Value

$this

$this whereDate(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null, string $boolean = 'and')

Add a "where date" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|null $operator
DateTimeInterface|string|null $value
string $boolean

Return Value

$this

$this orWhereDate(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null)

Add an "or where date" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|null $operator
DateTimeInterface|string|null $value

Return Value

$this

$this whereTime(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null, string $boolean = 'and')

Add a "where time" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|null $operator
DateTimeInterface|string|null $value
string $boolean

Return Value

$this

$this orWhereTime(Expression|string $column, DateTimeInterface|string|null $operator, DateTimeInterface|string|null $value = null)

Add an "or where time" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|null $operator
DateTimeInterface|string|null $value

Return Value

$this

$this whereDay(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where day" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value
string $boolean

Return Value

$this

$this orWhereDay(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where day" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value

Return Value

$this

$this whereMonth(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where month" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value
string $boolean

Return Value

$this

$this orWhereMonth(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where month" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value

Return Value

$this

$this whereYear(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null, string $boolean = 'and')

Add a "where year" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value
string $boolean

Return Value

$this

$this orWhereYear(Expression|string $column, DateTimeInterface|string|int|null $operator, DateTimeInterface|string|int|null $value = null)

Add an "or where year" statement to the query.

Parameters

Expression|string $column
DateTimeInterface|string|int|null $operator
DateTimeInterface|string|int|null $value

Return Value

$this

protected $this addDateBasedWhere(string $type, Expression|string $column, string $operator, mixed $value, string $boolean = 'and')

Add a date based (year, month, day, time) statement to the query.

Parameters

string $type
Expression|string $column
string $operator
mixed $value
string $boolean

Return Value

$this

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

Add a nested where statement to the query.

Parameters

Closure $callback
string $boolean

Return Value

$this

Builder forNestedWhere()

Create a new query instance for nested where condition.

Return Value

Builder

$this addNestedWhereQuery(Builder $query, string $boolean = 'and')

Add another query builder as a nested where to the query builder.

Parameters

Builder $query
string $boolean

Return Value

$this

protected $this whereSub(Expression|string $column, string $operator, $callback, string $boolean)

Add a full sub-select to the query.

Parameters

Expression|string $column
string $operator
$callback
string $boolean

Return Value

$this

$this whereExists($callback, string $boolean = 'and', bool $not = false)

Add an exists clause to the query.

Parameters

$callback
string $boolean
bool $not

Return Value

$this

$this orWhereExists($callback, bool $not = false)

Add an or exists clause to the query.

Parameters

$callback
bool $not

Return Value

$this

$this whereNotExists($callback, string $boolean = 'and')

Add a where not exists clause to the query.

Parameters

$callback
string $boolean

Return Value

$this

$this orWhereNotExists($callback)

Add a where not exists clause to the query.

Parameters

$callback

Return Value

$this

$this addWhereExistsQuery(Builder $query, string $boolean = 'and', bool $not = false)

Add an exists clause to the query.

Parameters

Builder $query
string $boolean
bool $not

Return Value

$this

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

Adds a where condition using row values.

Parameters

array $columns
string $operator
array $values
string $boolean

Return Value

$this

Exceptions

InvalidArgumentException

$this orWhereRowValues(array $columns, string $operator, array $values)

Adds an or where condition using row values.

Parameters

array $columns
string $operator
array $values

Return Value

$this

$this whereJsonContains(string $column, mixed $value, string $boolean = 'and', bool $not = false)

Add a "where JSON contains" clause to the query.

Parameters

string $column
mixed $value
string $boolean
bool $not

Return Value

$this

$this orWhereJsonContains(string $column, mixed $value)

Add an "or where JSON contains" clause to the query.

Parameters

string $column
mixed $value

Return Value

$this

$this whereJsonDoesntContain(string $column, mixed $value, string $boolean = 'and')

Add a "where JSON not contains" clause to the query.

Parameters

string $column
mixed $value
string $boolean

Return Value

$this

$this orWhereJsonDoesntContain(string $column, mixed $value)

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

Parameters

string $column
mixed $value

Return Value

$this

$this whereJsonOverlaps(string $column, mixed $value, string $boolean = 'and', bool $not = false)

Add a "where JSON overlaps" clause to the query.

Parameters

string $column
mixed $value
string $boolean
bool $not

Return Value

$this

$this orWhereJsonOverlaps(string $column, mixed $value)

Add an "or where JSON overlaps" clause to the query.

Parameters

string $column
mixed $value

Return Value

$this

$this whereJsonDoesntOverlap(string $column, mixed $value, string $boolean = 'and')

Add a "where JSON not overlap" clause to the query.

Parameters

string $column
mixed $value
string $boolean

Return Value

$this

$this orWhereJsonDoesntOverlap(string $column, mixed $value)

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

Parameters

string $column
mixed $value

Return Value

$this

$this whereJsonContainsKey(string $column, string $boolean = 'and', bool $not = false)

Add a clause that determines if a JSON path exists to the query.

Parameters

string $column
string $boolean
bool $not

Return Value

$this

$this orWhereJsonContainsKey(string $column)

Add an "or" clause that determines if a JSON path exists to the query.

Parameters

string $column

Return Value

$this

$this whereJsonDoesntContainKey(string $column, string $boolean = 'and')

Add a clause that determines if a JSON path does not exist to the query.

Parameters

string $column
string $boolean

Return Value

$this

$this orWhereJsonDoesntContainKey(string $column)

Add an "or" clause that determines if a JSON path does not exist to the query.

Parameters

string $column

Return Value

$this

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

Add a "where JSON length" clause to the query.

Parameters

string $column
mixed $operator
mixed $value
string $boolean

Return Value

$this

$this orWhereJsonLength(string $column, mixed $operator, mixed $value = null)

Add an "or where JSON length" clause to the query.

Parameters

string $column
mixed $operator
mixed $value

Return Value

$this

$this dynamicWhere(string $method, array $parameters)

Handles dynamic "where" clauses to the query.

Parameters

string $method
array $parameters

Return Value

$this

protected void addDynamic(string $segment, string $connector, array $parameters, int $index)

Add a single dynamic where clause statement to the query.

Parameters

string $segment
string $connector
array $parameters
int $index

Return Value

void

$this whereFullText(string|string[] $columns, string $value, array $options = [], string $boolean = 'and')

Add a "where fulltext" clause to the query.

Parameters

string|string[] $columns
string $value
array $options
string $boolean

Return Value

$this

$this orWhereFullText(string|string[] $columns, string $value, array $options = [])

Add a "or where fulltext" clause to the query.

Parameters

string|string[] $columns
string $value
array $options

Return Value

$this

$this whereAll(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where" clause to the query for multiple columns with "and" conditions between them.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value
string $boolean

Return Value

$this

$this orWhereAll(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query for multiple columns with "and" conditions between them.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value

Return Value

$this

$this whereAny(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where" clause to the query for multiple columns with "or" conditions between them.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value
string $boolean

Return Value

$this

$this orWhereAny(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query for multiple columns with "or" conditions between them.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value

Return Value

$this

$this whereNone(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null, string $boolean = 'and')

Add a "where not" clause to the query for multiple columns where none of the conditions should be true.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value
string $boolean

Return Value

$this

$this orWhereNone(Expression[]|Closure[]|string[] $columns, mixed $operator = null, mixed $value = null)

Add an "or where not" clause to the query for multiple columns where none of the conditions should be true.

Parameters

Expression[]|Closure[]|string[] $columns
mixed $operator
mixed $value

Return Value

$this

$this groupBy(array|Expression|string ...$groups)

Add a "group by" clause to the query.

Parameters

array|Expression|string ...$groups

Return Value

$this

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

Add a raw groupBy clause to the query.

Parameters

string $sql
array $bindings

Return Value

$this

$this having(Expression|Closure|string $column, string|int|float|null $operator = null, string|int|float|null $value = null, string $boolean = 'and')

Add a "having" clause to the query.

Parameters

Expression|Closure|string $column
string|int|float|null $operator
string|int|float|null $value
string $boolean

Return Value

$this

$this orHaving(Expression|Closure|string $column, string|int|float|null $operator = null, string|int|float|null $value = null)

Add an "or having" clause to the query.

Parameters

Expression|Closure|string $column
string|int|float|null $operator
string|int|float|null $value

Return Value

$this

$this havingNested(Closure $callback, string $boolean = 'and')

Add a nested having statement to the query.

Parameters

Closure $callback
string $boolean

Return Value

$this

$this addNestedHavingQuery(Builder $query, string $boolean = 'and')

Add another query builder as a nested having to the query builder.

Parameters

Builder $query
string $boolean

Return Value

$this

$this havingNull(string|array $columns, string $boolean = 'and', bool $not = false)

Add a "having null" clause to the query.

Parameters

string|array $columns
string $boolean
bool $not

Return Value

$this

$this orHavingNull(string $column)

Add an "or having null" clause to the query.

Parameters

string $column

Return Value

$this

$this havingNotNull(string|array $columns, string $boolean = 'and')

Add a "having not null" clause to the query.

Parameters

string|array $columns
string $boolean

Return Value

$this

$this orHavingNotNull(string $column)

Add an "or having not null" clause to the query.

Parameters

string $column

Return Value

$this

$this havingBetween(string $column, iterable $values, string $boolean = 'and', bool $not = false)

Add a "having between " clause to the query.

Parameters

string $column
iterable $values
string $boolean
bool $not

Return Value

$this

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

Add a raw having clause to the query.

Parameters

string $sql
array $bindings
string $boolean

Return Value

$this

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

Add a raw or having clause to the query.

Parameters

string $sql
array $bindings

Return Value

$this

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

Add an "order by" clause to the query.

Parameters

$column
string $direction

Return Value

$this

Exceptions

InvalidArgumentException

$this orderByDesc($column)

Add a descending "order by" clause to the query.

Parameters

$column

Return Value

$this

$this latest(Closure|Builder|Expression|string $column = 'created_at')

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

Parameters

Closure|Builder|Expression|string $column

Return Value

$this

$this oldest(Closure|Builder|Expression|string $column = 'created_at')

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

Parameters

Closure|Builder|Expression|string $column

Return Value

$this

$this inRandomOrder(string|int $seed = '')

Put the query's results in random order.

Parameters

string|int $seed

Return Value

$this

$this orderByRaw(string $sql, array $bindings = [])

Add a raw "order by" clause to the query.

Parameters

string $sql
array $bindings

Return Value

$this

$this skip(int $value)

Alias to set the "offset" value of the query.

Parameters

int $value

Return Value

$this

$this offset(int $value)

Set the "offset" value of the query.

Parameters

int $value

Return Value

$this

$this take(int $value)

Alias to set the "limit" value of the query.

Parameters

int $value

Return Value

$this

$this limit(int $value)

Set the "limit" value of the query.

Parameters

int $value

Return Value

$this

$this groupLimit(int $value, string $column)

Add a "group limit" clause to the query.

Parameters

int $value
string $column

Return Value

$this

$this forPage(int $page, int $perPage = 15)

Set the limit and offset for a given page.

Parameters

int $page
int $perPage

Return Value

$this

$this forPageBeforeId(int $perPage = 15, int|null $lastId = 0, string $column = 'id')

Constrain the query to the previous "page" of results before a given ID.

Parameters

int $perPage
int|null $lastId
string $column

Return Value

$this

$this forPageAfterId(int $perPage = 15, int|null $lastId = 0, string $column = 'id')

Constrain the query to the next "page" of results after a given ID.

Parameters

int $perPage
int|null $lastId
string $column

Return Value

$this

$this reorder(Closure|Builder|Expression|string|null $column = null, string $direction = 'asc')

Remove all existing orders and optionally add a new order.

Parameters

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

Return Value

$this

protected array removeExistingOrdersFor(string $column)

Get an array with all orders with a given column removed.

Parameters

string $column

Return Value

array

$this union($query, bool $all = false)

Add a union statement to the query.

Parameters

$query
bool $all

Return Value

$this

$this unionAll($query)

Add a union all statement to the query.

Parameters

$query

Return Value

$this

$this lock(string|bool $value = true)

Lock the selected rows in the table.

Parameters

string|bool $value

Return Value

$this

$this lockForUpdate()

Lock the selected rows in the table for updating.

Return Value

$this

$this sharedLock()

Share lock the selected rows in the table.

Return Value

$this

$this beforeQuery(callable $callback)

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

Parameters

callable $callback

Return Value

$this

void applyBeforeQueryCallbacks()

Invoke the "before query" modification callbacks.

Return Value

void

$this afterQuery(Closure $callback)

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

Parameters

Closure $callback

Return Value

$this

mixed applyAfterQueryCallbacks(mixed $result)

Invoke the "after query" modification callbacks.

Parameters

mixed $result

Return Value

mixed

string toSql()

Get the SQL representation of the query.

Return Value

string

string toRawSql()

Get the raw SQL representation of the query with embedded bindings.

Return Value

string

object|null find(int|string $id, array|string $columns = ['*'])

Execute a query for a single record by ID.

Parameters

int|string $id
array|string $columns

Return Value

object|null

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

No description

Parameters

$id
$columns
Closure|null $callback

mixed value(string $column)

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

Parameters

string $column

Return Value

mixed

mixed rawValue(string $expression, array $bindings = [])

Get a single expression value from the first result of a query.

Parameters

string $expression
array $bindings

Return Value

mixed

mixed soleValue(string $column)

Get a single column's value from the first result of a query if it's the sole matching record.

Parameters

string $column

Return Value

mixed

Exceptions

RecordsNotFoundException
MultipleRecordsFoundException

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

Execute the query as a "select" statement.

Parameters

array|string $columns

Return Value

stdClass>

protected array runSelect()

Run the query as a "select" statement against the connection.

Return Value

array

protected Collection withoutGroupLimitKeys(Collection $items)

Remove the group limit keys from the results in the collection.

Parameters

Collection $items

Return Value

Collection

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

Paginate the given query into a simple paginator.

Parameters

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

Return Value

LengthAwarePaginator

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

Get a paginator only supporting simple next and previous links.

This is more efficient on larger data-sets, etc.

Parameters

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

Return Value

Paginator

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

Get a paginator only supporting simple next and previous links.

This is more efficient on larger data-sets, etc.

Parameters

int|null $perPage
array|string $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

int getCountForPagination(array $columns = ['*'])

Get the count of the total records for the paginator.

Parameters

array $columns

Return Value

int

protected array runPaginationCountQuery(array $columns = ['*'])

Run a pagination count query.

Parameters

array $columns

Return Value

array

protected Builder cloneForPaginationCount()

Clone the existing query instance for usage in a pagination subquery.

Return Value

Builder

protected array withoutSelectAliases(array $columns)

Remove the column aliases since they will break count queries.

Parameters

array $columns

Return Value

array

stdClass> cursor()

Get a lazy collection for the given query.

Return Value

stdClass>

protected void enforceOrderBy()

Throw an exception if the query doesn't have an orderBy clause.

Return Value

void

Exceptions

RuntimeException

Collection<array-key,mixed> pluck(Expression|string $column, string|null $key = null)

Get a collection instance containing the values of a given column.

Parameters

Expression|string $column
string|null $key

Return Value

Collection<array-key,mixed>

protected string|null stripTableForPluck(string $column)

Strip off the table name or alias from a column identifier.

Parameters

string $column

Return Value

string|null

protected Collection pluckFromObjectColumn(array $queryResult, string $column, string $key)

Retrieve column values from rows represented as objects.

Parameters

array $queryResult
string $column
string $key

Return Value

Collection

protected Collection pluckFromArrayColumn(array $queryResult, string $column, string $key)

Retrieve column values from rows represented as arrays.

Parameters

array $queryResult
string $column
string $key

Return Value

Collection

string implode(string $column, string $glue = '')

Concatenate values of a given column as a string.

Parameters

string $column
string $glue

Return Value

string

bool exists()

Determine if any rows exist for the current query.

Return Value

bool

bool doesntExist()

Determine if no rows exist for the current query.

Return Value

bool

mixed existsOr(Closure $callback)

Execute the given callback if no rows exist for the current query.

Parameters

Closure $callback

Return Value

mixed

mixed doesntExistOr(Closure $callback)

Execute the given callback if rows exist for the current query.

Parameters

Closure $callback

Return Value

mixed

int count(Expression|string $columns = '*')

Retrieve the "count" result of the query.

Parameters

Expression|string $columns

Return Value

int

mixed min(Expression|string $column)

Retrieve the minimum value of a given column.

Parameters

Expression|string $column

Return Value

mixed

mixed max(Expression|string $column)

Retrieve the maximum value of a given column.

Parameters

Expression|string $column

Return Value

mixed

mixed sum(Expression|string $column)

Retrieve the sum of the values of a given column.

Parameters

Expression|string $column

Return Value

mixed

mixed avg(Expression|string $column)

Retrieve the average of the values of a given column.

Parameters

Expression|string $column

Return Value

mixed

mixed average(Expression|string $column)

Alias for the "avg" method.

Parameters

Expression|string $column

Return Value

mixed

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

Execute an aggregate function on the database.

Parameters

string $function
array $columns

Return Value

mixed

float|int numericAggregate(string $function, array $columns = ['*'])

Execute a numeric aggregate function on the database.

Parameters

string $function
array $columns

Return Value

float|int

protected $this setAggregate(string $function, array $columns)

Set the aggregate property without running the query.

Parameters

string $function
array $columns

Return Value

$this

protected mixed onceWithColumns(array $columns, callable $callback)

Execute the given callback while selecting the given columns.

After running the callback, the columns are reset to the original value.

Parameters

array $columns
callable $callback

Return Value

mixed

bool insert(array $values)

Insert new records into the database.

Parameters

array $values

Return Value

bool

int insertOrIgnore(array $values)

Insert new records into the database while ignoring errors.

Parameters

array $values

Return Value

int

int insertGetId(array $values, string|null $sequence = null)

Insert a new record and get the value of the primary key.

Parameters

array $values
string|null $sequence

Return Value

int

int insertUsing(array $columns, $query)

Insert new records into the table using a subquery.

Parameters

array $columns
$query

Return Value

int

int insertOrIgnoreUsing(array $columns, $query)

Insert new records into the table using a subquery while ignoring errors.

Parameters

array $columns
$query

Return Value

int

int update(array $values)

Update records in the database.

Parameters

array $values

Return Value

int

int updateFrom(array $values)

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

Parameters

array $values

Return Value

int

bool updateOrInsert(array $attributes, array|callable $values = [])

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

Parameters

array $attributes
array|callable $values

Return Value

bool

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 $column, float|int $amount = 1, array $extra = [])

Increment a column's value by a given amount.

Parameters

string $column
float|int $amount
array $extra

Return Value

int

Exceptions

InvalidArgumentException

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

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

Parameters

array $columns
array $extra

Return Value

int

Exceptions

InvalidArgumentException

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

Decrement a column's value by a given amount.

Parameters

string $column
float|int $amount
array $extra

Return Value

int

Exceptions

InvalidArgumentException

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

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

Parameters

array $columns
array $extra

Return Value

int

Exceptions

InvalidArgumentException

int delete(mixed $id = null)

Delete records from the database.

Parameters

mixed $id

Return Value

int

void truncate()

Run a truncate statement on the table.

Return Value

void

Builder newQuery()

Get a new instance of the join clause builder.

Return Value

Builder

protected Builder forSubQuery()

Create a new query instance for sub-query.

Return Value

Builder

array getColumns()

Get all of the query builder's columns in a text-only array with all expressions evaluated.

Return Value

array

Expression raw(mixed $value)

Create a raw database expression.

Parameters

mixed $value

Return Value

Expression

protected Collection getUnionBuilders()

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

Return Value

Collection

mixed getLimit()

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

Return Value

mixed

mixed getOffset()

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

Return Value

mixed

array getBindings()

Get the current query value bindings in a flattened array.

Return Value

array

array getRawBindings()

Get the raw array of bindings.

Return Value

array

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

Set the bindings on the query builder.

Parameters

array $bindings
string $type

Return Value

$this

Exceptions

InvalidArgumentException

$this addBinding(mixed $value, string $type = 'where')

Add a binding to the query.

Parameters

mixed $value
string $type

Return Value

$this

Exceptions

InvalidArgumentException

mixed castBinding(mixed $value)

Cast the given binding value.

Parameters

mixed $value

Return Value

mixed

$this mergeBindings(Builder $query)

Merge an array of bindings into our bindings.

Parameters

Builder $query

Return Value

$this

array cleanBindings(array $bindings)

Remove all of the expressions from a list of bindings.

Parameters

array $bindings

Return Value

array

protected mixed flattenValue(mixed $value)

Get a scalar type value from an unknown type of input.

Parameters

mixed $value

Return Value

mixed

protected string defaultKeyName()

Get the default key name of the table.

Return Value

string

ConnectionInterface getConnection()

Get the database connection instance.

Return Value

ConnectionInterface

Processor getProcessor()

Get the database query processor instance.

Return Value

Processor

Grammar getGrammar()

Get the query grammar instance.

Return Value

Grammar

$this useWritePdo()

Use the "write" PDO connection when executing the query.

Return Value

$this

protected bool isQueryable(mixed $value)

Determine if the value is a query builder instance or a Closure.

Parameters

mixed $value

Return Value

bool

Builder clone()

Clone the query.

Return Value

Builder

Builder cloneWithout(array $properties)

Clone the query without the given properties.

Parameters

array $properties

Return Value

Builder

Builder cloneWithoutBindings(array $except)

Clone the query without the given bindings.

Parameters

array $except

Return Value

Builder

$this dump(mixed ...$args)

Dump the current SQL and bindings.

Parameters

mixed ...$args

Return Value

$this

$this dumpRawSql()

Dump the raw current SQL with embedded bindings.

Return Value

$this

never dd()

Die and dump the current SQL and bindings.

Return Value

never

never ddRawSql()

Die and dump the current SQL with embedded bindings.

Return Value

never

$this on(Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null, string $boolean = 'and')

Add an "on" clause to the join.

On clauses can be chained, e.g.

$join->on('contacts.user_id', '=', 'users.id') ->on('contacts.info_id', '=', 'info.id')

will produce the following SQL:

on contacts.user_id = users.id and contacts.info_id = info.id

Parameters

Closure|Expression|string $first
string|null $operator
Expression|string|null $second
string $boolean

Return Value

$this

Exceptions

InvalidArgumentException

JoinClause orOn(Closure|Expression|string $first, string|null $operator = null, Expression|string|null $second = null)

Add an "or on" clause to the join.

Parameters

Closure|Expression|string $first
string|null $operator
Expression|string|null $second

Return Value

JoinClause

protected Builder newParentQuery()

Create a new parent query instance.

Return Value

Builder