JoinClause

class JoinClause extends Builder (View source)

Traits

BuildsQueries
ForwardsCalls
Macroable

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 $columns The columns that should be returned. from Builder
bool $distinct Indicates if the query returns distinct results. from Builder
string $from The table which the query is targeting. 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 $orders The orderings for the query. from Builder
int $limit The maximum number of records to return. from Builder
int $offset The number of records to skip. from Builder
array $unions The query union statements. from Builder
int $unionLimit The maximum number of union records to return. from Builder
int $unionOffset The number of union records to skip. from Builder
array $unionOrders The orderings for the union query. from Builder
string|bool $lock Indicates whether row locking is being used. from Builder
array $operators All of the available clause operators. from Builder
bool $useWritePdo Whether use write pdo for select. from Builder
string $type The type of join being performed.
string $table The table the join clause is joining to.

Methods

bool chunk(int $count, callable $callback)

Chunk the results of the query.

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

Execute a callback over each item while chunking.

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

Execute the query and get the first result.

from BuildsQueries
mixed|$this when(mixed $value, callable $callback, callable $default = null)

Apply the callback's query changes if the given "value" is true.

from BuildsQueries
Builder tap(Closure $callback)

Pass the query to a given callback.

from BuildsQueries
mixed|$this unless(mixed $value, callable $callback, callable $default = null)

Apply the callback's query changes if the given "value" is false.

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

Create a new length-aware paginator instance.

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

Create a new simple paginator instance.

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

Forward a method call to the given object.

from ForwardsCalls
static void throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

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

Register a custom macro.

from Macroable
static void mixin(object $mixin)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

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

Dynamically handle calls to the class.

from Macroable
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
Builder|Builder selectSub(Closure|Builder|string $query, string $as)

Add a subselect expression to the query.

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

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

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

Makes "from" fetch from a subquery.

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

Add a raw from clause to the query.

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

Creates a subquery and parse it.

from Builder
array parseSub(mixed $query)

Parse the subquery into SQL and bindings.

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

Set the table which the query is targeting.

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

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

Add a "join where" clause to the query.

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

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

Add a left join to the query.

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

Add a "join where" clause to the query.

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

Add a subquery left join to the query.

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

Add a right join to the query.

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

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

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

Add a subquery right join to the query.

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

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

Merge an array of where clauses and bindings.

from Builder
$this where(string|array|Closure $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
Builder|Builder orWhere(string|array|Closure $column, mixed $operator = null, mixed $value = null)

Add an "or where" clause to the query.

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

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

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

Add a raw where clause to the query.

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

Add a raw or where clause to the query.

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

Add a "where in" clause to the query.

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

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

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

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

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

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

from Builder
$this whereInSub(string $column, Closure $callback, string $boolean, bool $not)

Add a where in with a sub-select to the query.

from Builder
$this whereInExistingQuery(string $column, Builder|Builder $query, string $boolean, bool $not)

Add an external sub-select to the query.

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

Add a "where null" clause to the query.

from Builder
Builder|Builder orWhereNull(string $column)

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

from Builder
Builder|Builder whereNotNull(string $column, string $boolean = 'and')

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

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

Add a where between statement to the query.

from Builder
Builder|Builder orWhereBetween(string $column, array $values)

Add an or where between statement to the query.

from Builder
Builder|Builder whereNotBetween(string $column, array $values, string $boolean = 'and')

Add a where not between statement to the query.

from Builder
Builder|Builder orWhereNotBetween(string $column, array $values)

Add an or where not between statement to the query.

from Builder
Builder|Builder orWhereNotNull(string $column)

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

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

Add a "where date" statement to the query.

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

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

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

Add a "where time" statement to the query.

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

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

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

Add a "where day" statement to the query.

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

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

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

Add a "where month" statement to the query.

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

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

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

Add a "where year" statement to the query.

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

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

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

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

Add a nested where statement to the query.

from Builder
Builder forNestedWhere()

Create a new query instance for nested where condition.

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

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

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

Add a full sub-select to the query.

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

Add an exists clause to the query.

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

Add an or exists clause to the query.

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

Add a where not exists clause to the query.

from Builder
Builder|Builder orWhereNotExists(Closure $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 a 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 a "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 a "or where JSON not contains" clause 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 a "or where JSON length" clause to the query.

from Builder
$this dynamicWhere(string $method, string $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 groupBy(array ...$groups)

Add a "group by" clause to the query.

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

Add a "having" clause to the query.

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

Add a "or having" 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
Builder|Builder orHavingRaw(string $sql, array $bindings = [])

Add a raw or having clause to the query.

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

Add an "order by" clause to the query.

from Builder
$this orderByDesc(string $column)

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

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

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

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

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

from Builder
$this inRandomOrder(string $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
Builder|Builder 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
Builder|Builder 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
Builder|Builder forPage(int $page, int $perPage = 15)

Set the limit and offset for a given page.

from Builder
Builder|Builder 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
array removeExistingOrdersFor(string $column)

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

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

Add a union statement to the query.

from Builder
Builder|Builder unionAll(Builder|Closure $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
Builder lockForUpdate()

Lock the selected rows in the table for updating.

from Builder
Builder sharedLock()

Share lock the selected rows in the table.

from Builder
string toSql()

Get the SQL representation of the query.

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

Execute a query for a single record by ID.

from Builder
mixed value(string $column)

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

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

Execute the query as a "select" statement.

from Builder
array runSelect()

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

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

Paginate the given query into a simple paginator.

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

Get a paginator only supporting simple next and previous links.

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

Remove the column aliases since they will break count queries.

from Builder
Generator cursor()

Get a generator for the given query.

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

Chunk the results of a query by comparing numeric IDs.

from Builder
void enforceOrderBy()

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

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

Get an array with 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
Collection pluckFromObjectColumn(array $queryResult, string $column, string $key)

Retrieve column values from rows represented as objects.

from Builder
Collection 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
int count(string $columns = '*')

Retrieve the "count" result of the query.

from Builder
mixed min(string $column)

Retrieve the minimum value of a given column.

from Builder
mixed max(string $column)

Retrieve the maximum value of a given column.

from Builder
mixed sum(string $column)

Retrieve the sum of the values of a given column.

from Builder
mixed avg(string $column)

Retrieve the average of the values of a given column.

from Builder
mixed average(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 a new record into the database.

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

Update a record in the database.

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

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

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

Increment a column's value by a given amount.

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

Decrement a column's value by a given amount.

from Builder
int delete(mixed $id = null)

Delete a record from the database.

from Builder
void truncate()

Run a truncate statement on the table.

from Builder
Builder newQuery()

Get a new instance of the join clause builder.

Builder forSubQuery()

Create a new query instance for sub-query.

Expression raw(mixed $value)

Create a raw database expression.

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
$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
ConnectionInterface getConnection()

Get the database connection instance.

from Builder
Processor getProcessor()

Get the database query processor instance.

from Builder
Grammar getGrammar()

Get the query grammar instance.

from Builder
$this useWritePdo()

Use the write pdo for query.

from Builder
Builder cloneWithout(array $properties)

Clone the query without the given properties.

from Builder
Builder cloneWithoutBindings(array $except)

Clone the query without the given bindings.

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

Add an "on" clause to the join.

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

Add an "or on" clause to the join.

Details

bool chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

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

Execute a callback over each item while chunking.

Parameters

callable $callback
int $count

Return Value

bool

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

Execute the query and get the first result.

Parameters

array $columns

Return Value

Model|object|BuildsQueries|null

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

Apply the callback's query changes if the given "value" is true.

Parameters

mixed $value
callable $callback
callable $default

Return Value

mixed|$this

Builder tap(Closure $callback)

Pass the query to a given callback.

Parameters

Closure $callback

Return Value

Builder

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

Apply the callback's query changes if the given "value" is false.

Parameters

mixed $value
callable $callback
callable $default

Return Value

mixed|$this

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

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)

Mix another object into the class.

Parameters

object $mixin

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)

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

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

Exceptions

InvalidArgumentException

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

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

Exceptions

InvalidArgumentException

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

Add a raw from clause to the query.

Parameters

string $expression
mixed $bindings

Return Value

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

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

Set the table which the query is targeting.

Parameters

string $table

Return Value

$this

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

$this

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

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

Exceptions

InvalidArgumentException

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

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

Add a "join where" clause to the query.

Parameters

string $table
string $first
string $operator
string $second

Return Value

Builder|Builder

Builder|Builder leftJoinSub(Closure|Builder|string $query, string $as, 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
string $first
string|null $operator
string|null $second

Return Value

Builder|Builder

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

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

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

Parameters

string $table
string $first
string $operator
string $second

Return Value

Builder|Builder

Builder|Builder rightJoinSub(Closure|Builder|string $query, string $as, 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
string $first
string|null $operator
string|null $second

Return Value

Builder|Builder

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

void mergeWheres(array $wheres, array $bindings)

Merge an array of where clauses and bindings.

Parameters

array $wheres
array $bindings

Return Value

void

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

Add a basic where clause to the query.

Parameters

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

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

Add an "or where" clause to the query.

Parameters

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

Return Value

Builder|Builder

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

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

$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

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

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

$this

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

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

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

protected $this whereInSub(string $column, Closure $callback, string $boolean, bool $not)

Add a where in with a sub-select to the query.

Parameters

string $column
Closure $callback
string $boolean
bool $not

Return Value

$this

protected $this whereInExistingQuery(string $column, Builder|Builder $query, string $boolean, bool $not)

Add an external sub-select to the query.

Parameters

string $column
Builder|Builder $query
string $boolean
bool $not

Return Value

$this

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

Add a "where null" clause to the query.

Parameters

string $column
string $boolean
bool $not

Return Value

$this

Builder|Builder orWhereNull(string $column)

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

Parameters

string $column

Return Value

Builder|Builder

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

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

Parameters

string $column
string $boolean

Return Value

Builder|Builder

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

Add a where between statement to the query.

Parameters

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

Return Value

$this

Builder|Builder orWhereBetween(string $column, array $values)

Add an or where between statement to the query.

Parameters

string $column
array $values

Return Value

Builder|Builder

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

Add a where not between statement to the query.

Parameters

string $column
array $values
string $boolean

Return Value

Builder|Builder

Builder|Builder orWhereNotBetween(string $column, array $values)

Add an or where not between statement to the query.

Parameters

string $column
array $values

Return Value

Builder|Builder

Builder|Builder orWhereNotNull(string $column)

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

Parameters

string $column

Return Value

Builder|Builder

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

Add a "where date" statement to the query.

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $column
string $operator
DateTimeInterface|string $value

Return Value

Builder|Builder

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

Add a "where time" statement to the query.

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $column
string $operator
DateTimeInterface|string $value

Return Value

Builder|Builder

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

Add a "where day" statement to the query.

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $column
string $operator
DateTimeInterface|string $value

Return Value

Builder|Builder

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

Add a "where month" statement to the query.

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $column
string $operator
DateTimeInterface|string $value

Return Value

Builder|Builder

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

Add a "where year" statement to the query.

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder|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|Builder whereNested(Closure $callback, string $boolean = 'and')

Add a nested where statement to the query.

Parameters

Closure $callback
string $boolean

Return Value

Builder|Builder

Builder forNestedWhere()

Create a new query instance for nested where condition.

Return Value

Builder

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

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

Parameters

Builder|Builder $query
string $boolean

Return Value

$this

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

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

$this

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

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

Builder|Builder orWhereNotExists(Closure $callback)

Add a where not exists clause to the query.

Parameters

Closure $callback

Return Value

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

$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

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

Adds a 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 a "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 a "or where JSON not contains" clause to the query.

Parameters

string $column
mixed $value

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 a "or where JSON length" clause to the query.

Parameters

string $column
mixed $operator
mixed $value

Return Value

$this

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

Handles dynamic "where" clauses to the query.

Parameters

string $method
string $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 groupBy(array ...$groups)

Add a "group by" clause to the query.

Parameters

array ...$groups

Return Value

$this

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

$this

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

Add a "or having" clause to the query.

Parameters

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

Return Value

Builder|Builder

$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

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

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

Add an "order by" clause to the query.

Parameters

string $column
string $direction

Return Value

$this

$this orderByDesc(string $column)

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

Parameters

string $column

Return Value

$this

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

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

Parameters

string $column

Return Value

Builder|Builder

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

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

Parameters

string $column

Return Value

Builder|Builder

$this inRandomOrder(string $seed = '')

Put the query's results in random order.

Parameters

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

Builder|Builder skip(int $value)

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

Parameters

int $value

Return Value

Builder|Builder

$this offset(int $value)

Set the "offset" value of the query.

Parameters

int $value

Return Value

$this

Builder|Builder take(int $value)

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

Parameters

int $value

Return Value

Builder|Builder

$this limit(int $value)

Set the "limit" value of the query.

Parameters

int $value

Return Value

$this

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

Set the limit and offset for a given page.

Parameters

int $page
int $perPage

Return Value

Builder|Builder

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

Builder|Builder

protected array removeExistingOrdersFor(string $column)

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

Parameters

string $column

Return Value

array

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

Add a union statement to the query.

Parameters

Builder|Closure $query
bool $all

Return Value

Builder|Builder

Builder|Builder unionAll(Builder|Closure $query)

Add a union all statement to the query.

Parameters

Builder|Closure $query

Return Value

Builder|Builder

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

Lock the selected rows in the table.

Parameters

string|bool $value

Return Value

$this

Builder lockForUpdate()

Lock the selected rows in the table for updating.

Return Value

Builder

Builder sharedLock()

Share lock the selected rows in the table.

Return Value

Builder

string toSql()

Get the SQL representation of the query.

Return Value

string

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

Execute a query for a single record by ID.

Parameters

int $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 $columns = ['*'])

Execute the query as a "select" statement.

Parameters

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

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

Remove the column aliases since they will break count queries.

Parameters

array $columns

Return Value

array

Generator cursor()

Get a generator for the given query.

Return Value

Generator

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

Chunk the results of a query by comparing numeric IDs.

Parameters

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

Return Value

bool

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 an array with 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

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 a new record into the database.

Parameters

array $values

Return Value

bool

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

Update a record 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 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

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

int delete(mixed $id = null)

Delete a record 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

Expression raw(mixed $value)

Create a raw database expression.

Parameters

mixed $value

Return Value

Expression

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

$this mergeBindings(Builder $query)

Merge an array of bindings into our bindings.

Parameters

Builder $query

Return Value

$this

protected array cleanBindings(array $bindings)

Remove all of the expressions from a list of bindings.

Parameters

array $bindings

Return Value

array

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 for query.

Return Value

$this

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 on(Closure|string $first, string|null $operator = null, 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|string $first
string|null $operator
string|null $second
string $boolean

Return Value

$this

Exceptions

InvalidArgumentException

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

Add an "or on" clause to the join.

Parameters

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

Return Value

JoinClause

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Database/Query/JoinClause.html