Builder

class Builder (View source)

Properties

protected Builder $query The base query builder instance.
protected Model $model The model being queried.
protected array $eagerLoad The relationships that should be eager loaded.
protected array $macros All of the registered builder macros.
protected Closure $onDelete A replacement for the typical delete function.
protected array $passthru The methods that should be returned from query builder.

Methods

void __construct(Builder $query)

Create a new Eloquent query builder instance.

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

Find a model by its primary key.

Model|Collection|Builder findMany(array $id, array $columns = array('*'))

Find a model by its primary key.

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

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

Model|Builder|null first(array $columns = array('*'))

Execute the query and get the first result.

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

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

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

Execute the query as a "select" statement.

mixed pluck(string $column)

Pluck a single column from the database.

void chunk(int $count, callable $callback)

Chunk the results of the query.

array lists(string $column, string $key = null)

Get an array with the values of a given column.

Paginator paginate(int $perPage = null, array $columns = array('*'))

Get a paginator for the "select" statement.

Paginator groupedPaginate(Factory $paginator, int $perPage, array $columns)

Get a paginator for a grouped statement.

Paginator ungroupedPaginate(Factory $paginator, int $perPage, array $columns)

Get a paginator for an ungrouped statement.

Paginator simplePaginate(int $perPage = null, array $columns = array('*'))

Get a paginator only supporting simple next and previous links.

int update(array $values)

Update a record in the database.

int increment(string $column, int $amount = 1, array $extra = array())

Increment a column's value by a given amount.

int decrement(string $column, int $amount = 1, array $extra = array())

Decrement a column's value by a given amount.

array addUpdatedAtColumn(array $values)

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

mixed delete()

Delete a record from the database.

mixed forceDelete()

Run the default delete function on the builder.

void onDelete(Closure $callback)

Register a replacement for the default delete function.

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

Get the hydrated models without eager loading.

array eagerLoadRelations(array $models)

Eager load the relationships for the models.

array loadRelation(array $models, string $name, Closure $constraints)

Eagerly load the relationship on a set of models.

Relation getRelation(string $relation)

Get the relation instance for the given relation name.

array nestedRelations(string $relation)

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

bool isNested(string $name, string $relation)

Determine if the relationship is nested.

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

Add a basic where clause to the query.

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

Add an "or where" clause to the query.

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

Add a relationship count condition to the query.

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

Add nested relationship count conditions to the query.

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

Add a relationship count condition to the query.

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

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

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

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

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

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

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

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

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

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

void mergeWheresToHas(Builder $hasQuery, Relation $relation)

Merge the "wheres" from a relation query to a has query.

Builder getHasRelationQuery(string $relation)

Get the "has relation" base query instance.

$this with(mixed $relations)

Set the relationships that should be eager loaded.

array parseRelations(array $relations)

Parse a list of relations into individuals.

array parseNested(string $name, array $results)

Parse the nested relationships in a relation.

Builder callScope(string $scope, array $parameters)

Call the given model scope on the underlying model.

Builder|Builder getQuery()

Get the underlying query builder instance.

void setQuery(Builder $query)

Set the underlying query builder instance.

array getEagerLoads()

Get the relationships being eagerly loaded.

void setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

Model getModel()

Get the model instance being queried.

$this setModel(Model $model)

Set a model instance for the model being queried.

void macro(string $name, Closure $callback)

Extend the builder with a given callback.

Closure getMacro(string $name)

Get the given macro by name.

mixed __call(string $method, array $parameters)

Dynamically handle calls into the query instance.

void __clone()

Force a clone of the underlying query builder when cloning.

Details

void __construct(Builder $query)

Create a new Eloquent query builder instance.

Parameters

Builder $query

Return Value

void

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

Find a model by its primary key.

Parameters

mixed $id
array $columns

Return Value

Model|Builder|null

Model|Collection|Builder findMany(array $id, array $columns = array('*'))

Find a model by its primary key.

Parameters

array $id
array $columns

Return Value

Model|Collection|Builder

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

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

Parameters

mixed $id
array $columns

Return Value

Model|Builder

Exceptions

ModelNotFoundException

Model|Builder|null first(array $columns = array('*'))

Execute the query and get the first result.

Parameters

array $columns

Return Value

Model|Builder|null

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

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

Parameters

array $columns

Return Value

Model|Builder

Exceptions

ModelNotFoundException

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

Execute the query as a "select" statement.

Parameters

array $columns

Return Value

Collection|Builder[]

mixed pluck(string $column)

Pluck a single column from the database.

Parameters

string $column

Return Value

mixed

void chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

void

array lists(string $column, string $key = null)

Get an array with the values of a given column.

Parameters

string $column
string $key

Return Value

array

Paginator paginate(int $perPage = null, array $columns = array('*'))

Get a paginator for the "select" statement.

Parameters

int $perPage
array $columns

Return Value

Paginator

protected Paginator groupedPaginate(Factory $paginator, int $perPage, array $columns)

Get a paginator for a grouped statement.

Parameters

Factory $paginator
int $perPage
array $columns

Return Value

Paginator

protected Paginator ungroupedPaginate(Factory $paginator, int $perPage, array $columns)

Get a paginator for an ungrouped statement.

Parameters

Factory $paginator
int $perPage
array $columns

Return Value

Paginator

Paginator simplePaginate(int $perPage = null, array $columns = array('*'))

Get a paginator only supporting simple next and previous links.

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

Parameters

int $perPage
array $columns

Return Value

Paginator

int update(array $values)

Update a record in the database.

Parameters

array $values

Return Value

int

int increment(string $column, int $amount = 1, array $extra = array())

Increment a column's value by a given amount.

Parameters

string $column
int $amount
array $extra

Return Value

int

int decrement(string $column, int $amount = 1, array $extra = array())

Decrement a column's value by a given amount.

Parameters

string $column
int $amount
array $extra

Return Value

int

protected array addUpdatedAtColumn(array $values)

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

Parameters

array $values

Return Value

array

mixed delete()

Delete a record from the database.

Return Value

mixed

mixed forceDelete()

Run the default delete function on the builder.

Return Value

mixed

void onDelete(Closure $callback)

Register a replacement for the default delete function.

Parameters

Closure $callback

Return Value

void

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

Get the hydrated models without eager loading.

Parameters

array $columns

Return Value

Model[]

array eagerLoadRelations(array $models)

Eager load the relationships for the models.

Parameters

array $models

Return Value

array

protected array loadRelation(array $models, string $name, Closure $constraints)

Eagerly load the relationship on a set of models.

Parameters

array $models
string $name
Closure $constraints

Return Value

array

Relation getRelation(string $relation)

Get the relation instance for the given relation name.

Parameters

string $relation

Return Value

Relation

protected array nestedRelations(string $relation)

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

Parameters

string $relation

Return Value

array

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

Determine if the relationship is nested.

Parameters

string $name
string $relation

Return Value

bool

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

Add a basic where clause to the query.

Parameters

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

Return Value

$this

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

Add an "or where" clause to the query.

Parameters

string $column
string $operator
mixed $value

Return Value

Builder|Builder

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

Add a relationship count condition to the query.

Parameters

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

Return Value

Builder|Builder

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

Add nested relationship count conditions to the query.

Parameters

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

Return Value

Builder|Builder

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

Add a relationship count condition to the query.

Parameters

string $relation
string $boolean
Closure $callback

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $relation
Closure $callback

Return Value

Builder|Builder

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

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

Parameters

string $relation
string $operator
int $count

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder

protected void mergeWheresToHas(Builder $hasQuery, Relation $relation)

Merge the "wheres" from a relation query to a has query.

Parameters

Builder $hasQuery
Relation $relation

Return Value

void

protected Builder getHasRelationQuery(string $relation)

Get the "has relation" base query instance.

Parameters

string $relation

Return Value

Builder

$this with(mixed $relations)

Set the relationships that should be eager loaded.

Parameters

mixed $relations

Return Value

$this

protected array parseRelations(array $relations)

Parse a list of relations into individuals.

Parameters

array $relations

Return Value

array

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

Parse the nested relationships in a relation.

Parameters

string $name
array $results

Return Value

array

protected Builder callScope(string $scope, array $parameters)

Call the given model scope on the underlying model.

Parameters

string $scope
array $parameters

Return Value

Builder

Builder|Builder getQuery()

Get the underlying query builder instance.

Return Value

Builder|Builder

void setQuery(Builder $query)

Set the underlying query builder instance.

Parameters

Builder $query

Return Value

void

array getEagerLoads()

Get the relationships being eagerly loaded.

Return Value

array

void setEagerLoads(array $eagerLoad)

Set the relationships being eagerly loaded.

Parameters

array $eagerLoad

Return Value

void

Model getModel()

Get the model instance being queried.

Return Value

Model

$this setModel(Model $model)

Set a model instance for the model being queried.

Parameters

Model $model

Return Value

$this

void macro(string $name, Closure $callback)

Extend the builder with a given callback.

Parameters

string $name
Closure $callback

Return Value

void

Closure getMacro(string $name)

Get the given macro by name.

Parameters

string $name

Return Value

Closure

mixed __call(string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/4.2/Illuminate/Database/Eloquent/Builder.html