JoinClause
class JoinClause extends Builder
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
Connection | $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
Execute a callback over each item while chunking.
Execute the query and get the first result.
Apply the callback's query changes if the given "value" is true.
Apply the callback's query changes if the given "value" is false.
Create a new length-aware paginator instance.
Create a new simple paginator instance.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Add a new "raw" select expression to the query.
Add a join clause to the query.
Add a "join where" clause to the query.
Add a left join to the query.
Add a "join where" clause to the query.
Add a right join to the query.
Add a "right join where" clause to the query.
Add a "cross join" clause to the query.
Merge an array of where clauses and bindings.
Add a basic where clause to the query.
Add an array of where clauses to the query.
Prepare the value and operator for a where clause.
Determine if the given operator and value combination is legal.
Add an "or where" clause to the query.
Add a "where" clause comparing two columns to the query.
Add an "or where" clause comparing two columns to the query.
Add a raw where clause to the query.
Add a raw or where clause to the query.
Add a "where in" clause to the query.
Add a "where not in" clause to the query.
Add an "or where not in" clause to the query.
Add a where in with a sub-select to the query.
Add an external sub-select to the query.
Add a "where null" clause to the query.
Add an "or where null" clause to the query.
Add a "where not null" clause to the query.
Add a where between statement to the query.
Add an or where between statement to the query.
Add a where not between statement to the query.
Add an or where not between statement to the query.
Add an "or where not null" clause to the query.
Add a "where date" statement to the query.
Add an "or where date" statement to the query.
Add a "where time" statement to the query.
Add an "or where time" statement to the query.
Add a "where day" statement to the query.
Add a "where month" statement to the query.
Add a "where year" statement to the query.
Add a date based (year, month, day, time) statement to the query.
Add another query builder as a nested where to the query builder.
Add a full sub-select to the query.
Add an exists clause to the query.
Add a where not exists clause to the query.
Add an exists clause to the query.
Handles dynamic "where" clauses to the query.
Add a single dynamic where clause statement to the query.
Add a "having" clause to the query.
Add a "or having" clause to the query.
Add a raw having clause to the query.
Add a raw or having clause to the query.
Add an "order by" clause to the query.
Add an "order by" clause for a timestamp to the query.
Add an "order by" clause for a timestamp to the query.
Add a raw "order by" clause to the query.
Constrain the query to the next "page" of results after a given ID.
Get an array with all orders with a given column removed.
Execute a query for a single record by ID.
Get a single column's value from the first result of a query.
Paginate the given query into a simple paginator.
Get a paginator only supporting simple next and previous links.
Get the count of the total records for the paginator.
Remove the column aliases since they will break count queries.
Chunk the results of a query by comparing numeric IDs.
Get an array with the values of a given column.
Strip off the table name or alias from a column identifier.
Concatenate values of a given column as a string.
Execute an aggregate function on the database.
Execute a numeric aggregate function on the database.
Set the aggregate property without running the query.
Insert a new record and get the value of the primary key.
Insert or update a record matching the attributes, and fill it with values.
Increment a column's value by a given amount.
Decrement a column's value by a given amount.
Set the bindings on the query builder.
Remove all of the expressions from a list of bindings.
Clone the query without the given bindings.
Details
in
BuildsQueries at line 18
bool
chunk(int $count, callable $callback)
Chunk the results of the query.
in
BuildsQueries at line 56
bool
each(callable $callback, int $count = 1000)
Execute a callback over each item while chunking.
in
BuildsQueries at line 73
Model|BuildsQueries|null
first(array $columns = ['*'])
Execute the query and get the first result.
in
BuildsQueries at line 86
mixed
when(mixed $value, callable $callback, callable $default = null)
Apply the callback's query changes if the given "value" is true.
in
BuildsQueries at line 103
Builder
tap(Closure $callback)
Pass the query to a given callback.
in
BuildsQueries at line 116
mixed
unless(mixed $value, callable $callback, callable $default = null)
Apply the callback's query changes if the given "value" is false.
in
BuildsQueries at line 137
protected LengthAwarePaginator
paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
Create a new length-aware paginator instance.
in
BuildsQueries at line 153
protected Paginator
simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)
Create a new simple paginator instance.
in
Macroable at line 24
static void
macro(string $name, callable $macro)
Register a custom macro.
in
Macroable at line 35
static bool
hasMacro(string $name)
Checks if macro is registered.
in
Macroable at line 49
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 71
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 38
void
__construct(Builder $parentQuery, string $type, string $table)
Create a new join clause instance.
in
Builder at line 218
$this
select(array|mixed $columns = ['*'])
Set the columns to be selected.
in
Builder at line 232
Builder|Builder
selectRaw(string $expression, array $bindings = [])
Add a new "raw" select expression to the query.
in
Builder at line 252
Builder|Builder
selectSub(Closure|Builder|string $query, string $as)
Add a subselect expression to the query.
in
Builder at line 279
protected array
parseSubSelect(mixed $query)
Parse the sub-select query into SQL and bindings.
in
Builder at line 298
$this
addSelect(array|mixed $column)
Add a new select column to the query.
in
Builder at line 312
$this
distinct()
Force the query to only return distinct results.
in
Builder at line 325
$this
from(string $table)
Set the table which the query is targeting.
in
Builder at line 343
$this
join(string $table, string $first, string $operator = null, string $second = null, string $type = 'inner', bool $where = false)
Add a join clause to the query.
in
Builder at line 382
Builder|Builder
joinWhere(string $table, string $first, string $operator, string $second, string $type = 'inner')
Add a "join where" clause to the query.
in
Builder at line 396
Builder|Builder
leftJoin(string $table, string $first, string $operator = null, string $second = null)
Add a left join to the query.
in
Builder at line 410
Builder|Builder
leftJoinWhere(string $table, string $first, string $operator, string $second)
Add a "join where" clause to the query.
in
Builder at line 424
Builder|Builder
rightJoin(string $table, string $first, string $operator = null, string $second = null)
Add a right join to the query.
in
Builder at line 438
Builder|Builder
rightJoinWhere(string $table, string $first, string $operator, string $second)
Add a "right join where" clause to the query.
in
Builder at line 452
Builder|Builder
crossJoin(string $table, string $first = null, string $operator = null, string $second = null)
Add a "cross join" clause to the query.
in
Builder at line 470
void
mergeWheres(array $wheres, array $bindings)
Merge an array of where clauses and bindings.
in
Builder at line 488
$this
where(string|array|Closure $column, string $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
in
Builder at line 563
protected $this
addArrayOfWheres(array $column, string $boolean, string $method = 'where')
Add an array of where clauses to the query.
in
Builder at line 586
protected array
prepareValueAndOperator(string $value, string $operator, bool $useDefault = false)
Prepare the value and operator for a where clause.
in
Builder at line 606
protected bool
invalidOperatorAndValue(string $operator, mixed $value)
Determine if the given operator and value combination is legal.
Prevents using Null values with invalid operators.
in
Builder at line 618
protected bool
invalidOperator(string $operator)
Determine if the given operator is supported.
in
Builder at line 632
Builder|Builder
orWhere(string|array|Closure $column, string $operator = null, mixed $value = null)
Add an "or where" clause to the query.
in
Builder at line 646
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.
in
Builder at line 682
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.
in
Builder at line 695
$this
whereRaw(string $sql, mixed $bindings = [], string $boolean = 'and')
Add a raw where clause to the query.
in
Builder at line 711
Builder|Builder
orWhereRaw(string $sql, mixed $bindings = [])
Add a raw or where clause to the query.
in
Builder at line 725
$this
whereIn(string $column, mixed $values, string $boolean = 'and', bool $not = false)
Add a "where in" clause to the query.
in
Builder at line 777
Builder|Builder
orWhereIn(string $column, mixed $values)
Add an "or where in" clause to the query.
in
Builder at line 790
Builder|Builder
whereNotIn(string $column, mixed $values, string $boolean = 'and')
Add a "where not in" clause to the query.
in
Builder at line 802
Builder|Builder
orWhereNotIn(string $column, mixed $values)
Add an "or where not in" clause to the query.
in
Builder at line 816
protected $this
whereInSub(string $column, Closure $callback, string $boolean, bool $not)
Add a where in with a sub-select to the query.
in
Builder at line 841
protected $this
whereInExistingQuery(string $column, Builder|Builder $query, string $boolean, bool $not)
Add an external sub-select to the query.
in
Builder at line 860
$this
whereNull(string $column, string $boolean = 'and', bool $not = false)
Add a "where null" clause to the query.
in
Builder at line 875
Builder|Builder
orWhereNull(string $column)
Add an "or where null" clause to the query.
in
Builder at line 887
Builder|Builder
whereNotNull(string $column, string $boolean = 'and')
Add a "where not null" clause to the query.
in
Builder at line 901
$this
whereBetween(string $column, array $values, string $boolean = 'and', bool $not = false)
Add a where between statement to the query.
in
Builder at line 919
Builder|Builder
orWhereBetween(string $column, array $values)
Add an or where between statement to the query.
in
Builder at line 932
Builder|Builder
whereNotBetween(string $column, array $values, string $boolean = 'and')
Add a where not between statement to the query.
in
Builder at line 944
Builder|Builder
orWhereNotBetween(string $column, array $values)
Add an or where not between statement to the query.
in
Builder at line 955
Builder|Builder
orWhereNotNull(string $column)
Add an "or where not null" clause to the query.
in
Builder at line 969
Builder|Builder
whereDate(string $column, string $operator, mixed $value = null, string $boolean = 'and')
Add a "where date" statement to the query.
in
Builder at line 986
Builder|Builder
orWhereDate(string $column, string $operator, string $value)
Add an "or where date" statement to the query.
in
Builder at line 1000
Builder|Builder
whereTime(string $column, string $operator, int $value, string $boolean = 'and')
Add a "where time" statement to the query.
in
Builder at line 1013
Builder|Builder
orWhereTime(string $column, string $operator, int $value)
Add an "or where time" statement to the query.
in
Builder at line 1027
Builder|Builder
whereDay(string $column, string $operator, mixed $value = null, string $boolean = 'and')
Add a "where day" statement to the query.
in
Builder at line 1045
Builder|Builder
whereMonth(string $column, string $operator, mixed $value = null, string $boolean = 'and')
Add a "where month" statement to the query.
in
Builder at line 1063
Builder|Builder
whereYear(string $column, string $operator, mixed $value = null, string $boolean = 'and')
Add a "where year" statement to the query.
in
Builder at line 1082
protected $this
addDateBasedWhere(string $type, string $column, string $operator, int $value, string $boolean = 'and')
Add a date based (year, month, day, time) statement to the query.
in
Builder at line 1098
Builder|Builder
whereNested(Closure $callback, string $boolean = 'and')
Add a nested where statement to the query.
in
Builder at line 1110
Builder
forNestedWhere()
Create a new query instance for nested where condition.
in
Builder at line 1122
$this
addNestedWhereQuery(Builder|Builder $query, string $boolean = 'and')
Add another query builder as a nested where to the query builder.
in
Builder at line 1144
protected $this
whereSub(string $column, string $operator, Closure $callback, string $boolean)
Add a full sub-select to the query.
in
Builder at line 1170
$this
whereExists(Closure $callback, string $boolean = 'and', bool $not = false)
Add an exists clause to the query.
in
Builder at line 1189
Builder|Builder
orWhereExists(Closure $callback, bool $not = false)
Add an or exists clause to the query.
in
Builder at line 1201
Builder|Builder
whereNotExists(Closure $callback, string $boolean = 'and')
Add a where not exists clause to the query.
in
Builder at line 1212
Builder|Builder
orWhereNotExists(Closure $callback)
Add a where not exists clause to the query.
in
Builder at line 1225
$this
addWhereExistsQuery(Builder $query, string $boolean = 'and', bool $not = false)
Add an exists clause to the query.
in
Builder at line 1243
$this
dynamicWhere(string $method, string $parameters)
Handles dynamic "where" clauses to the query.
in
Builder at line 1288
protected void
addDynamic(string $segment, string $connector, array $parameters, int $index)
Add a single dynamic where clause statement to the query.
in
Builder at line 1304
$this
groupBy(array ...$groups)
Add a "group by" clause to the query.
in
Builder at line 1325
$this
having(string $column, string $operator = null, string $value = null, string $boolean = 'and')
Add a "having" clause to the query.
in
Builder at line 1360
Builder|Builder
orHaving(string $column, string $operator = null, string $value = null)
Add a "or having" clause to the query.
in
Builder at line 1373
$this
havingRaw(string $sql, array $bindings = [], string $boolean = 'and')
Add a raw having clause to the query.
in
Builder at line 1391
Builder|Builder
orHavingRaw(string $sql, array $bindings = [])
Add a raw or having clause to the query.
in
Builder at line 1403
$this
orderBy(string $column, string $direction = 'asc')
Add an "order by" clause to the query.
in
Builder at line 1419
$this
orderByDesc(string $column)
Add a descending "order by" clause to the query.
in
Builder at line 1430
Builder|Builder
latest(string $column = 'created_at')
Add an "order by" clause for a timestamp to the query.
in
Builder at line 1441
Builder|Builder
oldest(string $column = 'created_at')
Add an "order by" clause for a timestamp to the query.
in
Builder at line 1452
$this
inRandomOrder(string $seed = '')
Put the query's results in random order.
in
Builder at line 1464
$this
orderByRaw(string $sql, array $bindings = [])
Add a raw "order by" clause to the query.
in
Builder at line 1481
Builder|Builder
skip(int $value)
Alias to set the "offset" value of the query.
in
Builder at line 1492
$this
offset(int $value)
Set the "offset" value of the query.
in
Builder at line 1507
Builder|Builder
take(int $value)
Alias to set the "limit" value of the query.
in
Builder at line 1518
$this
limit(int $value)
Set the "limit" value of the query.
in
Builder at line 1536
Builder|Builder
forPage(int $page, int $perPage = 15)
Set the limit and offset for a given page.
in
Builder at line 1549
Builder|Builder
forPageAfterId(int $perPage = 15, int $lastId = 0, string $column = 'id')
Constrain the query to the next "page" of results after a given ID.
in
Builder at line 1564
protected array
removeExistingOrdersFor(string $column)
Get an array with all orders with a given column removed.
in
Builder at line 1580
Builder|Builder
union(Builder|Closure $query, bool $all = false)
Add a union statement to the query.
in
Builder at line 1599
Builder|Builder
unionAll(Builder|Closure $query)
Add a union all statement to the query.
in
Builder at line 1610
$this
lock(string|bool $value = true)
Lock the selected rows in the table.
in
Builder at line 1646
string
toSql()
Get the SQL representation of the query.
in
Builder at line 1658
mixed|Builder
find(int $id, array $columns = ['*'])
Execute a query for a single record by ID.
in
Builder at line 1669
mixed
value(string $column)
Get a single column's value from the first result of a query.
in
Builder at line 1682
Collection
get(array $columns = ['*'])
Execute the query as a "select" statement.
in
Builder at line 1702
protected array
runSelect()
Run the query as a "select" statement against the connection.
in
Builder at line 1718
LengthAwarePaginator
paginate(int $perPage = 15, array $columns = ['*'], string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
in
Builder at line 1743
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.
in
Builder at line 1761
int
getCountForPagination(array $columns = ['*'])
Get the count of the total records for the paginator.
in
Builder at line 1785
protected array
runPaginationCountQuery(array $columns = ['*'])
Run a pagination count query.
in
Builder at line 1799
protected array
withoutSelectAliases(array $columns)
Remove the column aliases since they will break count queries.
in
Builder at line 1832
bool
chunkById(int $count, callable $callback, string $column = 'id', string $alias = null)
Chunk the results of a query by comparing numeric IDs.
in
Builder at line 1872
protected void
enforceOrderBy()
Throw an exception if the query doesn't have an orderBy clause.
in
Builder at line 1886
Collection
pluck(string $column, string|null $key = null)
Get an array with the values of a given column.
in
Builder at line 1905
protected string|null
stripTableForPluck(string $column)
Strip off the table name or alias from a column identifier.
in
Builder at line 1917
string
implode(string $column, string $glue = '')
Concatenate values of a given column as a string.
in
Builder at line 1927
bool
exists()
Determine if any rows exist for the current query.
in
Builder at line 1951
int
count(string $columns = '*')
Retrieve the "count" result of the query.
in
Builder at line 1962
mixed
min(string $column)
Retrieve the minimum value of a given column.
in
Builder at line 1973
mixed
max(string $column)
Retrieve the maximum value of a given column.
in
Builder at line 1984
mixed
sum(string $column)
Retrieve the sum of the values of a given column.
in
Builder at line 1997
mixed
avg(string $column)
Retrieve the average of the values of a given column.
in
Builder at line 2008
mixed
average(string $column)
Alias for the "avg" method.
in
Builder at line 2020
mixed
aggregate(string $function, array $columns = ['*'])
Execute an aggregate function on the database.
in
Builder at line 2039
float|int
numericAggregate(string $function, array $columns = ['*'])
Execute a numeric aggregate function on the database.
in
Builder at line 2068
protected $this
setAggregate(string $function, array $columns)
Set the aggregate property without running the query.
in
Builder at line 2087
bool
insert(array $values)
Insert a new record into the database.
in
Builder at line 2127
int
insertGetId(array $values, string $sequence = null)
Insert a new record and get the value of the primary key.
in
Builder at line 2142
int
update(array $values)
Update a record in the database.
in
Builder at line 2158
bool
updateOrInsert(array $attributes, array $values = [])
Insert or update a record matching the attributes, and fill it with values.
in
Builder at line 2175
int
increment(string $column, int $amount = 1, array $extra = [])
Increment a column's value by a given amount.
in
Builder at line 2196
int
decrement(string $column, int $amount = 1, array $extra = [])
Decrement a column's value by a given amount.
in
Builder at line 2215
int
delete(mixed $id = null)
Delete a record from the database.
in
Builder at line 2234
void
truncate()
Run a truncate statement on the table.
at line 96
Builder
newQuery()
Get a new instance of the join clause builder.
in
Builder at line 2257
Expression
raw(mixed $value)
Create a raw database expression.
in
Builder at line 2267
array
getBindings()
Get the current query value bindings in a flattened array.
in
Builder at line 2277
array
getRawBindings()
Get the raw array of bindings.
in
Builder at line 2291
$this
setBindings(array $bindings, string $type = 'where')
Set the bindings on the query builder.
in
Builder at line 2311
$this
addBinding(mixed $value, string $type = 'where')
Add a binding to the query.
in
Builder at line 2332
$this
mergeBindings(Builder $query)
Merge an array of bindings into our bindings.
in
Builder at line 2345
protected array
cleanBindings(array $bindings)
Remove all of the expressions from a list of bindings.
in
Builder at line 2357
ConnectionInterface
getConnection()
Get the database connection instance.
in
Builder at line 2387
$this
useWritePdo()
Use the write pdo for query.
in
Builder at line 2400
Builder
cloneWithout(array $except)
Clone the query without the given properties.
in
Builder at line 2415
Builder
cloneWithoutBindings(array $except)
Clone the query without the given bindings.
at line 69
$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
at line 86
JoinClause
orOn(Closure|string $first, string|null $operator = null, string|null $second = null)
Add an "or on" clause to the join.