class Builder implements Builder (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
ConnectionInterface $connection

The database connection instance.

Grammar $grammar

The database query grammar instance.

Processor $processor

The database query post processor instance.

array $bindings

The current query value bindings.

array $aggregate

An aggregate function and column to be run.

array $columns

The columns that should be returned.

bool|array $distinct

Indicates if the query returns distinct results.

string $from

The table which the query is targeting.

array $joins

The table joins for the query.

array $wheres

The where constraints for the query.

array $groups

The groupings for the query.

array $havings

The having constraints for the query.

array $orders

The orderings for the query.

int $limit

The maximum number of records to return.

int $offset

The number of records to skip.

array $unions

The query union statements.

int $unionLimit

The maximum number of union records to return.

int $unionOffset

The number of union records to skip.

array $unionOrders

The orderings for the union query.

string|bool $lock

Indicates whether row locking is being used.

array $beforeQueryCallbacks

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

string[] $operators

All of the available clause operators.

bool $useWritePdo

Whether to use write pdo for the select.

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.

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

Execute the query and get the first result.

Model|object|BuildsQueries|null
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.

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 void
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 mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Handle dynamic method calls into the method.

void
__construct(ConnectionInterface $connection, Grammar $grammar = null, Processor $processor = null)

Create a new query builder instance.

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

Set the columns to be selected.

selectSub(Closure|Builder|string $query, string $as)

Add a subselect expression to the query.

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

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

fromSub(Closure|Builder|string $query, string $as)

Makes "from" fetch from a subquery.

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

Add a raw from clause to the query.

array
createSub(Closure|Builder|string $query)

Creates a subquery and parse it.

array
parseSub(mixed $query)

Parse the subquery into SQL and bindings.

mixed
prependDatabaseNameIfCrossDatabaseQuery(mixed $query)

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

addSelect(array|mixed $column)

Add a new select column to the query.

distinct()

Force the query to only return distinct results.

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

Set the table which the query is targeting.

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

Add a join clause to the query.

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

Add a "join where" clause to the query.

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

Add a subquery join clause to the query.

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

Add a left join to the query.

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

Add a "join where" clause to the query.

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

Add a subquery left join to the query.

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

Add a right join to the query.

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

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

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

Add a subquery right join to the query.

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

Add a "cross join" clause to the query.

crossJoinSub(Closure|Builder|string $query, string $as)

Add a subquery cross join to the query.

newJoinClause(Builder $parentQuery, string $type, string $table)

Get a new join clause.

mergeWheres(array $wheres, array $bindings)

Merge an array of where clauses and bindings.

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

Add a basic where clause to the query.

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

Add an array of where clauses to the query.

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

Prepare the value and operator for a where clause.

bool
invalidOperatorAndValue(string $operator, mixed $value)

Determine if the given operator and value combination is legal.

bool
invalidOperator(string $operator)

Determine if the given operator is supported.

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

Add an "or where" clause to the query.

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

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

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

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

Add a raw where clause to the query.

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

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

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

Add a "where in" clause to the query.

orWhereIn(string $column, mixed $values)

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

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

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

orWhereNotIn(string $column, mixed $values)

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

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

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

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

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

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

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

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

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

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

Add a "where null" clause to the query.

orWhereNull(string|array $column)

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

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

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

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

Add a where between statement to the query.

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

Add a where between statement using columns to the query.

orWhereBetween(string $column, iterable $values)

Add an or where between statement to the query.

orWhereBetweenColumns(string $column, array $values)

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

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

Add a where not between statement to the query.

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

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

orWhereNotBetween(string $column, iterable $values)

Add an or where not between statement to the query.

orWhereNotBetweenColumns(string $column, array $values)

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

orWhereNotNull(string $column)

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

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

Add a "where date" statement to the query.

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

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

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

Add a "where time" statement to the query.

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

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

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

Add a "where day" statement to the query.

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

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

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

Add a "where month" statement to the query.

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

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

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

Add a "where year" statement to the query.

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

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

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

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

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

Add a nested where statement to the query.

forNestedWhere()

Create a new query instance for nested where condition.

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

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

$this
whereSub(string $column, string $operator, Closure $callback, string $boolean)

Add a full sub-select to the query.

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

Add an exists clause to the query.

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

Add an or exists clause to the query.

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

Add a where not exists clause to the query.

orWhereNotExists(Closure $callback)

Add a where not exists clause to the query.

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

Add an exists clause to the query.

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

Adds a where condition using row values.

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

Adds an or where condition using row values.

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

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

orWhereJsonContains(string $column, mixed $value)

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

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

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

orWhereJsonDoesntContain(string $column, mixed $value)

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

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

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

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

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

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

Handles dynamic "where" clauses to the query.

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

Add a single dynamic where clause statement to the query.

groupBy(array|string ...$groups)

Add a "group by" clause to the query.

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

Add a raw groupBy clause to the query.

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

Add a "having" clause to the query.

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

Add an "or having" clause to the query.

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

Add a "having null" clause to the query.

orHavingNull(string $column)

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

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

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

orHavingNotNull(string $column)

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

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

Add a "having between" clause to the query.

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

Add a raw having clause to the query.

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

Add a raw or having clause to the query.

orderBy(Closure|Expression|Builder|string $column, string $direction = 'asc')

Add an "order by" clause to the query.

orderByDesc(Closure|Expression|Builder|string $column)

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

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

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

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

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

inRandomOrder(string $seed = '')

Put the query's results in random order.

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

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

skip(int $value)

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

offset(int $value)

Set the "offset" value of the query.

take(int $value)

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

limit(int $value)

Set the "limit" value of the query.

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

No description

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

No description

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

No description

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

No description

array
removeExistingOrdersFor(string $column)

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

union(Builder|Closure $query, bool $all = false)

No description

unionAll(Builder|Closure $query)

No description

lock(string|bool $value = true)

No description

lockForUpdate()

No description

sharedLock()

No description

$this
beforeQuery(callable $callback)

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

void
applyBeforeQueryCallbacks()

Invoke the "before query" modification callbacks.

string
toSql()

Get the SQL representation of the query.

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

Execute a query for a single record by ID.

mixed
value(string $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.

array
runSelect()

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

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

Paginate the given query into a simple paginator.

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

Get a paginator only supporting simple next and previous links.

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

Get a paginator only supporting simple next and previous links.

ensureOrderForCursorPagination(bool $shouldReverse = false)

Ensure the proper order by required for cursor pagination.

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

Get the count of the total records for the paginator.

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

Run a pagination count query.

cloneForPaginationCount()

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

array
withoutSelectAliases(array $columns)

Remove the column aliases since they will break count queries.

cursor()

Get a lazy collection for the given query.

void
enforceOrderBy()

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

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

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

string|null
stripTableForPluck(string $column)

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

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

Retrieve column values from rows represented as objects.

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

Retrieve column values from rows represented as arrays.

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

Concatenate values of a given column as a string.

bool
exists()

Determine if any rows exist for the current query.

bool
doesntExist()

Determine if no rows exist for the current query.

mixed
existsOr(Closure $callback)

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

mixed
doesntExistOr(Closure $callback)

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

int
count(string $columns = '*')

Retrieve the "count" result of the query.

mixed
min(string $column)

Retrieve the minimum value of a given column.

mixed
max(string $column)

Retrieve the maximum value of a given column.

mixed
sum(string $column)

Retrieve the sum of the values of a given column.

mixed
avg(string $column)

Retrieve the average of the values of a given column.

mixed
average(string $column)

Alias for the "avg" method.

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

Execute an aggregate function on the database.

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

Execute a numeric aggregate function on the database.

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

Set the aggregate property without running the query.

mixed
onceWithColumns(array $columns, callable $callback)

Execute the given callback while selecting the given columns.

bool
insert(array $values)

Insert new records into the database.

int
insertOrIgnore(array $values)

Insert new records into the database while ignoring errors.

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

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

int
insertUsing(array $columns, Closure|Builder|string $query)

Insert new records into the table using a subquery.

int
update(array $values)

Update records in the database.

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

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

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

Insert new records or update the existing ones.

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

Increment a column's value by a given amount.

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

Decrement a column's value by a given amount.

int
delete(mixed $id = null)

Delete records from the database.

void
truncate()

Run a truncate statement on the table.

newQuery()

No description

forSubQuery()

Create a new query instance for a sub-query.

raw(mixed $value)

No description

array
getBindings()

No description

array
getRawBindings()

No description

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

No description

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

No description

mergeBindings(Builder $query)

No description

array
cleanBindings(array $bindings)

No description

mixed
flattenValue(mixed $value)

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

string
defaultKeyName()

Get the default key name of the table.

getProcessor()

No description

getGrammar()

No description

useWritePdo()

No description

bool
isQueryable(mixed $value)

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

clone()

No description

cloneWithout(array $properties)

No description

cloneWithoutBindings(array $except)

No description

$this
dump()

Dump the current SQL and bindings.

void
dd()

Die and dump the current SQL and bindings.

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

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|object|BuildsQueries|null 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|object|BuildsQueries|null

Exceptions

RecordsNotFoundException
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

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

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

void

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

Handle dynamic method calls into the method.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(ConnectionInterface $connection, Grammar $grammar = null, Processor $processor = null)

Create a new query builder instance.

Parameters

ConnectionInterface $connection
Grammar $grammar
Processor $processor

Return Value

void

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

Set the columns to be selected.

Parameters

array|mixed $columns

Return Value

Builder

Builder selectSub(Closure|Builder|string $query, string $as)

Add a subselect expression to the query.

Parameters

Closure|Builder|string $query
string $as

Return Value

Builder

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

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

Parameters

string $expression
array $bindings

Return Value

Builder

Builder fromSub(Closure|Builder|string $query, string $as)

Makes "from" fetch from a subquery.

Parameters

Closure|Builder|string $query
string $as

Return Value

Builder

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

Add a raw from clause to the query.

Parameters

string $expression
mixed $bindings

Return Value

Builder

protected array createSub(Closure|Builder|string $query)

Creates a subquery and parse it.

Parameters

Closure|Builder|string $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

Builder addSelect(array|mixed $column)

Add a new select column to the query.

Parameters

array|mixed $column

Return Value

Builder

Builder distinct()

Force the query to only return distinct results.

Return Value

Builder

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

Set the table which the query is targeting.

Parameters

Closure|Builder|string $table
string|null $as

Return Value

Builder

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

Add a join clause to the query.

Parameters

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

Return Value

Builder

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

Add a "join where" clause to the query.

Parameters

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

Return Value

Builder

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

Add a subquery join clause to the query.

Parameters

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

Return Value

Builder

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

Add a left join to the query.

Parameters

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

Return Value

Builder

Builder leftJoinWhere(string $table, Closure|string $first, string $operator, string $second)

Add a "join where" clause to the query.

Parameters

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

Return Value

Builder

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

Add a subquery left join to the query.

Parameters

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

Return Value

Builder

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

Add a right join to the query.

Parameters

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

Return Value

Builder

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

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

Parameters

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

Return Value

Builder

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

Add a subquery right join to the query.

Parameters

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

Return Value

Builder

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

Add a "cross join" clause to the query.

Parameters

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

Return Value

Builder

Builder crossJoinSub(Closure|Builder|string $query, string $as)

Add a subquery cross join to the query.

Parameters

Closure|Builder|string $query
string $as

Return Value

Builder

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

Get a new join clause.

Parameters

Builder $parentQuery
string $type
string $table

Return Value

JoinClause

Builder mergeWheres(array $wheres, array $bindings)

Merge an array of where clauses and bindings.

Parameters

array $wheres
array $bindings

Return Value

Builder

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

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

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

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

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

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

Return Value

Builder

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

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

Parameters

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

Return Value

Builder

Builder 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

Builder

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

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

Parameters

string $sql
mixed $bindings

Return Value

Builder

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

Add a "where in" clause to the query.

Parameters

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

Return Value

Builder

Builder orWhereIn(string $column, mixed $values)

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

Parameters

string $column
mixed $values

Return Value

Builder

Builder whereNotIn(string $column, mixed $values, string $boolean = 'and')

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

Parameters

string $column
mixed $values
string $boolean

Return Value

Builder

Builder orWhereNotIn(string $column, mixed $values)

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

Parameters

string $column
mixed $values

Return Value

Builder

Builder 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

Builder

Builder 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

Builder

Builder 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

Builder

Builder 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

Builder

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

Add a "where null" clause to the query.

Parameters

string|array $columns
string $boolean
bool $not

Return Value

Builder

Builder orWhereNull(string|array $column)

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

Parameters

string|array $column

Return Value

Builder

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

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

Parameters

string|array $columns
string $boolean

Return Value

Builder

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

Add a where between statement to the query.

Parameters

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

Return Value

Builder

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

Add a where between statement using columns to the query.

Parameters

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

Return Value

Builder

Builder orWhereBetween(string $column, iterable $values)

Add an or where between statement to the query.

Parameters

string $column
iterable $values

Return Value

Builder

Builder orWhereBetweenColumns(string $column, array $values)

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

Parameters

string $column
array $values

Return Value

Builder

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

Add a where not between statement to the query.

Parameters

string $column
iterable $values
string $boolean

Return Value

Builder

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

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

Parameters

string $column
array $values
string $boolean

Return Value

Builder

Builder orWhereNotBetween(string $column, iterable $values)

Add an or where not between statement to the query.

Parameters

string $column
iterable $values

Return Value

Builder

Builder orWhereNotBetweenColumns(string $column, array $values)

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

Parameters

string $column
array $values

Return Value

Builder

Builder orWhereNotNull(string $column)

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

Parameters

string $column

Return Value

Builder

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

Add a "where date" statement to the query.

Parameters

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

Return Value

Builder

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

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

Parameters

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

Return Value

Builder

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

Add a "where time" statement to the query.

Parameters

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

Return Value

Builder

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

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

Parameters

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

Return Value

Builder

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

Add a "where day" statement to the query.

Parameters

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

Return Value

Builder

Builder orWhereDay(string $column, string $operator, DateTimeInterface|string|null $value = null)

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

Parameters

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

Return Value

Builder

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

Add a "where month" statement to the query.

Parameters

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

Return Value

Builder

Builder orWhereMonth(string $column, string $operator, DateTimeInterface|string|null $value = null)

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

Parameters

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

Return Value

Builder

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

Add a "where year" statement to the query.

Parameters

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

Return Value

Builder

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

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

Parameters

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

Return Value

Builder

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

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

Parameters

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

Return Value

$this

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

Add a nested where statement to the query.

Parameters

Closure $callback
string $boolean

Return Value

Builder

Builder forNestedWhere()

Create a new query instance for nested where condition.

Return Value

Builder

Builder 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

Builder

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

Add a full sub-select to the query.

Parameters

string $column
string $operator
Closure $callback
string $boolean

Return Value

$this

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

Add an exists clause to the query.

Parameters

Closure $callback
string $boolean
bool $not

Return Value

Builder

Builder orWhereExists(Closure $callback, bool $not = false)

Add an or exists clause to the query.

Parameters

Closure $callback
bool $not

Return Value

Builder

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

Add a where not exists clause to the query.

Parameters

Closure $callback
string $boolean

Return Value

Builder

Builder orWhereNotExists(Closure $callback)

Add a where not exists clause to the query.

Parameters

Closure $callback

Return Value

Builder

$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

Builder 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

Builder

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

Adds an or where condition using row values.

Parameters

array $columns
string $operator
array $values

Return Value

Builder

Builder 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

Builder

Builder orWhereJsonContains(string $column, mixed $value)

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

Parameters

string $column
mixed $value

Return Value

Builder

Builder 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

Builder

Builder orWhereJsonDoesntContain(string $column, mixed $value)

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

Parameters

string $column
mixed $value

Return Value

Builder

Builder 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

Builder

Builder 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

Builder

$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

Builder groupBy(array|string ...$groups)

Add a "group by" clause to the query.

Parameters

array|string ...$groups

Return Value

Builder

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

Add a raw groupBy clause to the query.

Parameters

string $sql
array $bindings

Return Value

Builder

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

Add a "having" clause to the query.

Parameters

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

Return Value

Builder

Builder orHaving(string $column, string|null $operator = null, string|null $value = null)

Add an "or having" clause to the query.

Parameters

string $column
string|null $operator
string|null $value

Return Value

Builder

Builder 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

Builder

Builder orHavingNull(string $column)

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

Parameters

string $column

Return Value

Builder

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

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

Parameters

string|array $columns
string $boolean

Return Value

Builder

Builder orHavingNotNull(string $column)

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

Parameters

string $column

Return Value

Builder

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

Add a "having between" clause to the query.

Parameters

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

Return Value

Builder

Builder 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

Builder

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

Add a raw or having clause to the query.

Parameters

string $sql
array $bindings

Return Value

Builder

Builder orderBy(Closure|Expression|Builder|string $column, string $direction = 'asc')

Add an "order by" clause to the query.

Parameters

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

Return Value

Builder

Builder orderByDesc(Closure|Expression|Builder|string $column)

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

Parameters

Closure|Expression|Builder|string $column

Return Value

Builder

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

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 = 'created_at')

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

Parameters

Closure|Expression|Builder|string $column

Return Value

Builder

Builder inRandomOrder(string $seed = '')

Put the query's results in random order.

Parameters

string $seed

Return Value

Builder

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

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

Parameters

string $sql
array $bindings

Return Value

Builder

Builder skip(int $value)

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

Parameters

int $value

Return Value

Builder

Builder offset(int $value)

Set the "offset" value of the query.

Parameters

int $value

Return Value

Builder

Builder take(int $value)

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

Parameters

int $value

Return Value

Builder

Builder limit(int $value)

Set the "limit" value of the query.

Parameters

int $value

Return Value

Builder

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

No description

Parameters

int $page
int $perPage

Return Value

Builder

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

No description

Parameters

int $perPage
int|null $lastId
string $column

Return Value

Builder

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

No description

Parameters

int $perPage
int|null $lastId
string $column

Return Value

Builder

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

No description

Parameters

string|null $column
string $direction

Return Value

Builder

protected array removeExistingOrdersFor(string $column)

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

Parameters

string $column

Return Value

array

Builder union(Builder|Closure $query, bool $all = false)

No description

Parameters

Builder|Closure $query
bool $all

Return Value

Builder

Builder unionAll(Builder|Closure $query)

No description

Parameters

Builder|Closure $query

Return Value

Builder

Builder lock(string|bool $value = true)

No description

Parameters

string|bool $value

Return Value

Builder

Builder lockForUpdate()

No description

Return Value

Builder

Builder sharedLock()

No description

Return Value

Builder

$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

string toSql()

Get the SQL representation of the query.

Return Value

string

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

Execute a query for a single record by ID.

Parameters

int|string $id
array $columns

Return Value

mixed|Builder

mixed value(string $column)

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

Parameters

string $column

Return Value

mixed

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

Execute the query as a "select" statement.

Parameters

array|string $columns

Return Value

Collection

protected array runSelect()

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

Return Value

array

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

Paginate the given query into a simple paginator.

Parameters

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

Return Value

LengthAwarePaginator

Paginator simplePaginate(int $perPage = 15, array $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 $columns
string $pageName
int|null $page

Return Value

Paginator

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

LazyCollection cursor()

Get a lazy collection for the given query.

Return Value

LazyCollection

protected void enforceOrderBy()

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

Return Value

void

Exceptions

RuntimeException

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

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

Parameters

string $column
string|null $key

Return Value

Collection

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(string $columns = '*')

Retrieve the "count" result of the query.

Parameters

string $columns

Return Value

int

mixed min(string $column)

Retrieve the minimum value of a given column.

Parameters

string $column

Return Value

mixed

mixed max(string $column)

Retrieve the maximum value of a given column.

Parameters

string $column

Return Value

mixed

mixed sum(string $column)

Retrieve the sum of the values of a given column.

Parameters

string $column

Return Value

mixed

mixed avg(string $column)

Retrieve the average of the values of a given column.

Parameters

string $column

Return Value

mixed

mixed average(string $column)

Alias for the "avg" method.

Parameters

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, Closure|Builder|string $query)

Insert new records into the table using a subquery.

Parameters

array $columns
Closure|Builder|string $query

Return Value

int

int update(array $values)

Update records in the database.

Parameters

array $values

Return Value

int

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

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

Parameters

array $attributes
array $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 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 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()

No description

Return Value

Builder

protected Builder forSubQuery()

Create a new query instance for a sub-query.

Return Value

Builder

Expression raw(mixed $value)

No description

Parameters

mixed $value

Return Value

Expression

array getBindings()

No description

Return Value

array

array getRawBindings()

No description

Return Value

array

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

No description

Parameters

array $bindings
string $type

Return Value

Builder

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

No description

Parameters

mixed $value
string $type

Return Value

Builder

Builder mergeBindings(Builder $query)

No description

Parameters

Builder $query

Return Value

Builder

array cleanBindings(array $bindings)

No description

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

No description

Return Value

ConnectionInterface

Processor getProcessor()

No description

Return Value

Processor

Grammar getGrammar()

No description

Return Value

Grammar

Builder useWritePdo()

No description

Return Value

Builder

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

No description

Return Value

Builder

Builder cloneWithout(array $properties)

No description

Parameters

array $properties

Return Value

Builder

Builder cloneWithoutBindings(array $except)

No description

Parameters

array $except

Return Value

Builder

$this dump()

Dump the current SQL and bindings.

Return Value

$this

void dd()

Die and dump the current SQL and bindings.

Return Value

void