class Builder (View source)
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. | |
array | removedScopes() Get an array of global scopes that were removed from the query. | |
Model|Collection|Builder[]|Builder|null | find(mixed $id, array $columns = array('*')) Find a model by its primary key. | |
Collection | findMany(array $ids, array $columns = array('*')) Find multiple models by their primary keys. | |
Model|Collection | findOrFail(mixed $id, array $columns = array('*')) Find a model by its primary key or throw an exception. | |
Model | findOrNew(mixed $id, array $columns = array('*')) Find a model by its primary key or return fresh model instance. | |
Model | firstOrNew(array $attributes) Get the first record matching the attributes or instantiate it. | |
Model | firstOrCreate(array $attributes, array $values = array()) Get the first record matching the attributes or create it. | |
Model | 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. | |
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 | value(string $column) Get a single column's value from the first result of a query. | |
Generator | cursor() Get a generator for the given 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. | |
Collection | pluck(string $column, string|null $key = null) Get an array with the values of a given column. | |
LengthAwarePaginator | paginate(int $perPage = null, array $columns = array('*'), string $pageName = 'page', int|null $page = null) Paginate the given query. | |
Paginator | simplePaginate(int $perPage = null, array $columns = array('*'), string $pageName = 'page', int|null $page = null) 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. | |
Relation | getRelation(string $name) Get the relation instance for the given relation name. | |
$this | when(bool $value, Closure $callback, Closure $default = null) Apply the callback's query changes if the given "value" is true. | |
$this | where(string|Closure $column, string $operator = null, mixed $value = null, string $boolean = 'and') Add a basic where clause to the query. | |
Builder|Builder | orWhere(string|Closure $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 / exists condition to the query. | |
Builder|Builder | doesntHave(string $relation, string $boolean = 'and', Closure $callback = null) Add a relationship count / exists condition to the query. | |
Builder|Builder | whereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1) Add a relationship count / exists condition to the query with where clauses. | |
Builder|Builder | whereDoesntHave(string $relation, Closure $callback = null) Add a relationship count / exists condition to the query with where clauses. | |
Builder|Builder | orHas(string $relation, string $operator = '>=', int $count = 1) Add a relationship count / exists condition to the query with an "or". | |
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". | |
Builder|Builder | mergeModelDefinedRelationConstraints(Builder $relation) Merge the constraints from a relation query to the current query. | |
$this | with(mixed $relations) Set the relationships that should be eager loaded. | |
$this | without(mixed $relations) Prevent the specified relations from being eager loaded. | |
$this | withCount(mixed $relations) Add subselect queries to count the relations. | |
mixed | scopes(array $scopes) Add the given scopes to the current builder instance. | |
Builder|Builder | applyScopes() Apply the scopes to the Eloquent builder instance and return it. | |
Builder | getQuery() Get the underlying query builder instance. | |
Builder | 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. | |
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. |
Create a new Eloquent query builder instance.
Remove a registered global scope.
Remove all or passed registered global scopes.
Get an array of global scopes that were removed from the query.
Find a model by its primary key.
Find multiple models by their primary keys.
Find a model by its primary key or throw an exception.
Find a model by its primary key or return fresh model instance.
Get the first record matching the attributes or instantiate it.
Get the first record matching the attributes or create it.
Create or update a record matching the attributes, and fill it with values.
Execute the query and get the first result or throw an exception.
Execute the query as a "select" statement.
Get a single column's value from the first result of a query.
Get a generator for the given query.
Chunk the results of the query.
Chunk the results of a query by comparing numeric IDs.
Execute a callback over each item while chunking.
Get an array with the values of a given column.
Paginate the given query.
Paginate the given query into a simple paginator.
Update a record in the database.
Increment a column's value by a given amount.
Decrement a column's value by a given amount.
Delete a record from the database.
Run the default delete function on the builder.
Register a replacement for the default delete function.
Get the hydrated models without eager loading.
Eager load the relationships for the models.
Get the relation instance for the given relation name.
Apply the callback's query changes if the given "value" is true.
Add a basic where clause to the query.
Add an "or where" clause to the query.
Add a relationship count / exists condition to the query.
Add a relationship count / exists condition to the query.
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with an "or".
Add a relationship count / exists condition to the query with where clauses and an "or".
Merge the constraints from a relation query to the current query.
Set the relationships that should be eager loaded.
Prevent the specified relations from being eager loaded.
Add subselect queries to count the relations.
Add the given scopes to the current builder instance.
Get the underlying query builder instance.
Get a base query builder instance.
Set the underlying query builder instance.
Get the relationships being eagerly loaded.
Set the relationships being eagerly loaded.
Get the model instance being queried.
Set a model instance for the model being queried.
Extend the builder with a given callback.
Get the given macro by name.
Dynamically handle calls into the query instance.
Force a clone of the underlying query builder when cloning.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Database/Eloquent/Builder.html