class Builder (View source)

Methods

void
__construct( Builder $query)

Create a new Eloquent query builder instance.

$this
withGlobalScope( string $identifier, Scope|Closure $scope)

Register a new global scope.

$this
withoutGlobalScope( Scope|string $scope)

Remove a registered global scope.

$this
withoutGlobalScopes( array $scopes = null)

Remove all or passed registered global scopes.

find( mixed $id, array $columns = array('*'))

Find a model by its primary key.

findMany( array $ids, array $columns = array('*'))

Find multiple models by their primary keys.

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

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

findOrNew( mixed $id, array $columns = array('*'))

Find a model by its primary key or return fresh model instance.

firstOrNew( array $attributes)

Get the first record matching the attributes or instantiate it.

firstOrCreate( array $attributes)

Get the first record matching the attributes or create it.

updateOrCreate( array $attributes, array $values = array())

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

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

Execute the query and get the first result.

firstOrFail( array $columns = array('*'))

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

get( array $columns = array('*'))

Execute the query as a "select" statement.

mixed
value( string $column)

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

bool
chunk( int $count, callable $callback)

Chunk the results of the query.

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

Chunk the results of a query by comparing numeric IDs.

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

Execute a callback over each item while chunking.

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

Get an array with the values of a given column.

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

Alias for the "pluck" method.

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

Paginate the given query.

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

Paginate the given query into a simple paginator.

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.

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.

getRelation( string $name)

Get the relation instance for the given relation name.

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

Add a basic where clause to the query.

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

Add an "or where" clause to the query.

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

Add a relationship count / exists condition to the query.

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

Add a relationship count / exists condition to the query.

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

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

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

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

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

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

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

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

$this
with( mixed $relations)

Set the relationships that should be eager loaded.

applyScopes()

Apply the scopes to the Eloquent builder instance and return it.

getQuery()

Get the underlying query builder instance.

toBase()

Get a base query builder instance.

$this
setQuery( Builder $query)

Set the underlying query builder instance.

array
getEagerLoads()

Get the relationships being eagerly loaded.

$this
setEagerLoads( array $eagerLoad)

Set the relationships being eagerly loaded.

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.

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

at line line 74
void __construct( Builder $query)

Create a new Eloquent query builder instance.

Parameters

Builder $query

Return Value

void

at line line 86
$this withGlobalScope( string $identifier, Scope|Closure $scope)

Register a new global scope.

Parameters

string $identifier
Scope|Closure $scope

Return Value

$this

at line line 103
$this withoutGlobalScope( Scope|string $scope)

Remove a registered global scope.

Parameters

Scope|string $scope

Return Value

$this

at line line 126
$this withoutGlobalScopes( array $scopes = null)

Remove all or passed registered global scopes.

Parameters

array $scopes

Return Value

$this

at line line 146
Model|Collection|Builder[]|Builder|null find( mixed $id, array $columns = array('*'))

Find a model by its primary key.

Parameters

mixed $id
array $columns

Return Value

Model|Collection|Builder[]|Builder|null

at line line 164
Collection findMany( array $ids, array $columns = array('*'))

Find multiple models by their primary keys.

Parameters

array $ids
array $columns

Return Value

Collection

at line line 184
Model|Collection 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|Collection

Exceptions

ModelNotFoundException

at line line 206
Model findOrNew( mixed $id, array $columns = array('*'))

Find a model by its primary key or return fresh model instance.

Parameters

mixed $id
array $columns

Return Value

Model

at line line 221
Model firstOrNew( array $attributes)

Get the first record matching the attributes or instantiate it.

Parameters

array $attributes

Return Value

Model

at line line 236
Model firstOrCreate( array $attributes)

Get the first record matching the attributes or create it.

Parameters

array $attributes

Return Value

Model

at line line 256
Model updateOrCreate( array $attributes, array $values = array())

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

Parameters

array $attributes
array $values

Return Value

Model

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

Execute the query and get the first result.

Parameters

array $columns

Return Value

Model|Builder|null

at line line 284
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

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

Execute the query as a "select" statement.

Parameters

array $columns

Return Value

Collection|Builder[]

at line line 321
mixed value( string $column)

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

Parameters

string $column

Return Value

mixed

at line line 337
bool chunk( int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

at line line 365
bool chunkById( int $count, callable $callback, string $column = 'id')

Chunk the results of a query by comparing numeric IDs.

Parameters

int $count
callable $callback
string $column

Return Value

bool

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

Execute a callback over each item while chunking.

Parameters

callable $callback
int $count

Return Value

bool

at line line 413
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

at line line 440
Collection lists( string $column, string $key = null)

Alias for the "pluck" method.

Parameters

string $column
string $key

Return Value

Collection

at line line 456
LengthAwarePaginator paginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page', int|null $page = null)

Paginate the given query.

Parameters

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

Return Value

LengthAwarePaginator

Exceptions

InvalidArgumentException

at line line 481
Paginator simplePaginate( int $perPage = null, array $columns = array('*'), string $pageName = 'page')

Paginate the given query into a simple paginator.

Parameters

int $perPage
array $columns
string $pageName

Return Value

Paginator

at line line 501
int update( array $values)

Update a record in the database.

Parameters

array $values

Return Value

int

at line line 514
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

at line line 529
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

at line line 558
mixed delete()

Delete a record from the database.

Return Value

mixed

at line line 572
mixed forceDelete()

Run the default delete function on the builder.

Return Value

mixed

at line line 583
void onDelete( Closure $callback)

Register a replacement for the default delete function.

Parameters

Closure $callback

Return Value

void

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

Get the hydrated models without eager loading.

Parameters

array $columns

Return Value

Model[]

at line line 609
array eagerLoadRelations( array $models)

Eager load the relationships for the models.

Parameters

array $models

Return Value

array

at line line 658
Relation getRelation( string $name)

Get the relation instance for the given relation name.

Parameters

string $name

Return Value

Relation

at line line 724
$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

at line line 747
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

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

Add a relationship count / exists condition to the query.

Parameters

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

Return Value

Builder|Builder

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

Add a relationship count / exists condition to the query.

Parameters

string $relation
string $boolean
Closure $callback

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder|Builder

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

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

Parameters

string $relation
Closure $callback

Return Value

Builder|Builder

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

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

Parameters

string $relation
string $operator
int $count

Return Value

Builder|Builder

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

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

Parameters

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

Return Value

Builder|Builder

at line line 974
$this with( mixed $relations)

Set the relationships that should be eager loaded.

Parameters

mixed $relations

Return Value

$this

at line line 1079
Builder|Builder applyScopes()

Apply the scopes to the Eloquent builder instance and return it.

Return Value

Builder|Builder

at line line 1218
Builder|Builder getQuery()

Get the underlying query builder instance.

Return Value

Builder|Builder

at line line 1228
Builder toBase()

Get a base query builder instance.

Return Value

Builder

at line line 1239
$this setQuery( Builder $query)

Set the underlying query builder instance.

Parameters

Builder $query

Return Value

$this

at line line 1251
array getEagerLoads()

Get the relationships being eagerly loaded.

Return Value

array

at line line 1262
$this setEagerLoads( array $eagerLoad)

Set the relationships being eagerly loaded.

Parameters

array $eagerLoad

Return Value

$this

at line line 1274
Model getModel()

Get the model instance being queried.

Return Value

Model

at line line 1285
$this setModel( Model $model)

Set a model instance for the model being queried.

Parameters

Model $model

Return Value

$this

at line line 1301
void macro( string $name, Closure $callback)

Extend the builder with a given callback.

Parameters

string $name
Closure $callback

Return Value

void

at line line 1312
Closure getMacro( string $name)

Get the given macro by name.

Parameters

string $name

Return Value

Closure

at line line 1324
mixed __call( string $method, array $parameters)

Dynamically handle calls into the query instance.

Parameters

string $method
array $parameters

Return Value

mixed

at line line 1350
void __clone()

Force a clone of the underlying query builder when cloning.

Return Value

void