Builder
class Builder (View source)
Traits
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. | |
static protected array | $macros | All of the globally registered builder macros. | |
protected array | $localMacros | All of the locally 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. | |
protected array | $scopes | Applied global scopes. | |
protected array | $removedScopes | Removed global scopes. |
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.
Add a relationship count / exists condition to the query.
Add nested relationship count / exists conditions to the query.
Add a relationship count / exists condition to the query with an "or".
Add a relationship count / exists condition to the query.
Add a relationship count / exists condition to the query with an "or".
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with where clauses and an "or".
Add a relationship count / exists condition to the query with where clauses.
Add a relationship count / exists condition to the query with where clauses and an "or".
Add subselect queries to count the relations.
Add the "has" condition where clause to the query.
Merge the where constraints from another query to the current query.
Add a sub-query count clause to this query.
Get the "has relation" base query instance.
Check if we can run an "exists" query to optimize performance.
Remove all or passed registered global scopes.
Get an array of global scopes that were removed from the query.
Add a where clause on the primary key to the query.
Create a collection of models from plain arrays.
Create a collection of models from a raw 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.
Get a single column's value from the first result of a query.
Execute the query as a "select" statement.
Eager load the relationships for the models.
Eagerly load the relationship on a set of models.
Get the relation instance for the given relation name.
Get the deeply nested relations for a given top-level relation.
Determine if the relationship is nested.
Chunk the results of a query by comparing numeric IDs.
Add a generic "order by" clause if the query doesn't already have one.
Get an array with the values of a given column.
Paginate the given query.
Paginate the given query into a simple paginator.
Save a new model and return the instance. Allow mass-assignment.
Update a record in the database.
Increment a column's value by a given amount.
Decrement a column's value by a given amount.
Add the "updated at" column to an array of values.
Delete a record from the database.
Run the default delete function on the builder.
Call the given local model scopes.
Apply the scopes to the Eloquent builder instance and return it.
Apply the given scope on the current builder instance.
Nest where conditions by slicing them at the given where count.
Slice where conditions at the given offset and add them to the query as a nested condition.
Create a where array with nested where conditions.
Set the relationships that should be eager loaded.
Prevent the specified relations from being eager loaded.
Create a new instance of the model being queried.
Parse a list of relations into individuals.
Create a constraint to select the given columns for the relation.
Parse the nested relationships in a relation.
Get the relationships being eagerly loaded.
Set the relationships being eagerly loaded.
Dynamically handle calls into the query instance.
Dynamically handle calls into the query instance.
Force a clone of the underlying query builder when cloning.
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 QueriesRelationships at line 25
Builder|QueriesRelationships
has(string $relation, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure $callback = null)
Add a relationship count / exists condition to the query.
in QueriesRelationships at line 68
protected Builder|QueriesRelationships
hasNested(string $relations, string $operator = '>=', int $count = 1, string $boolean = 'and', Closure|null $callback = null)
Add nested relationship count / exists conditions to the query.
Sets up recursive call to whereHas until we finish the nested relation.
in QueriesRelationships at line 92
Builder|QueriesRelationships
orHas(string $relation, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with an "or".
in QueriesRelationships at line 105
Builder|QueriesRelationships
doesntHave(string $relation, string $boolean = 'and', Closure $callback = null)
Add a relationship count / exists condition to the query.
in QueriesRelationships at line 116
Builder|QueriesRelationships
orDoesntHave(string $relation)
Add a relationship count / exists condition to the query with an "or".
in QueriesRelationships at line 130
Builder|QueriesRelationships
whereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with where clauses.
in QueriesRelationships at line 144
Builder|QueriesRelationships
orWhereHas(string $relation, Closure $callback = null, string $operator = '>=', int $count = 1)
Add a relationship count / exists condition to the query with where clauses and an "or".
in QueriesRelationships at line 156
Builder|QueriesRelationships
whereDoesntHave(string $relation, Closure $callback = null)
Add a relationship count / exists condition to the query with where clauses.
in QueriesRelationships at line 168
Builder|QueriesRelationships
orWhereDoesntHave(string $relation, Closure $callback = null)
Add a relationship count / exists condition to the query with where clauses and an "or".
in QueriesRelationships at line 179
$this
withCount(mixed $relations)
Add subselect queries to count the relations.
in QueriesRelationships at line 237
protected Builder|QueriesRelationships
addHasWhere(Builder $hasQuery, Relation $relation, string $operator, int $count, string $boolean)
Add the "has" condition where clause to the query.
in QueriesRelationships at line 252
Builder|QueriesRelationships
mergeConstraintsFrom(Builder $from)
Merge the where constraints from another query to the current query.
in QueriesRelationships at line 277
protected $this
addWhereCountQuery(Builder $query, string $operator = '>=', int $count = 1, string $boolean = 'and')
Add a sub-query count clause to this query.
in QueriesRelationships at line 295
protected Relation
getRelationWithoutConstraints(string $relation)
Get the "has relation" base query instance.
in QueriesRelationships at line 309
protected bool
canUseExistsForExistenceCheck(string $operator, int $count)
Check if we can run an "exists" query to optimize performance.
at line 117
$this
withGlobalScope(string $identifier, Scope|Closure $scope)
Register a new global scope.
at line 153
$this
withoutGlobalScopes(array $scopes = null)
Remove all or passed registered global scopes.
at line 171
array
removedScopes()
Get an array of global scopes that were removed from the query.
at line 182
$this
whereKey(mixed $id)
Add a where clause on the primary key to the query.
at line 202
$this
where(string|array|Closure $column, string $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
at line 225
Builder|Builder
orWhere(string|array|Closure $column, string $operator = null, mixed $value = null)
Add an "or where" clause to the query.
at line 236
Collection
hydrate(array $items)
Create a collection of models from plain arrays.
at line 252
Collection
fromQuery(string $query, array $bindings = [])
Create a collection of models from a raw query.
at line 266
Model|Collection|Builder[]|Builder|null
find(mixed $id, array $columns = ['*'])
Find a model by its primary key.
at line 282
Collection
findMany(array $ids, array $columns = ['*'])
Find multiple models by their primary keys.
at line 300
Model|Collection
findOrFail(mixed $id, array $columns = ['*'])
Find a model by its primary key or throw an exception.
at line 324
Model
findOrNew(mixed $id, array $columns = ['*'])
Find a model by its primary key or return fresh model instance.
at line 340
Model
firstOrNew(array $attributes, array $values = [])
Get the first record matching the attributes or instantiate it.
at line 356
Model
firstOrCreate(array $attributes, array $values = [])
Get the first record matching the attributes or create it.
at line 374
Model
updateOrCreate(array $attributes, array $values = [])
Create or update a record matching the attributes, and fill it with values.
at line 389
Model|Builder
firstOrFail(array $columns = ['*'])
Execute the query and get the first result or throw an exception.
at line 405
Model|Builder|mixed
firstOr(Closure|array $columns = ['*'], Closure $callback = null)
Execute the query and get the first result or call a callback.
at line 426
mixed
value(string $column)
Get a single column's value from the first result of a query.
at line 439
Collection|Builder[]
get(array $columns = ['*'])
Execute the query as a "select" statement.
at line 459
Model[]
getModels(array $columns = ['*'])
Get the hydrated models without eager loading.
at line 472
array
eagerLoadRelations(array $models)
Eager load the relationships for the models.
at line 494
protected array
eagerLoadRelation(array $models, string $name, Closure $constraints)
Eagerly load the relationship on a set of models.
at line 520
Relation
getRelation(string $name)
Get the relation instance for the given relation name.
at line 551
protected array
relationsNestedUnder(string $relation)
Get the deeply nested relations for a given top-level relation.
at line 574
protected bool
isNestedUnder(string $relation, string $name)
Determine if the relationship is nested.
at line 600
bool
chunkById(int $count, callable $callback, string $column = null, string|null $alias = null)
Chunk the results of a query by comparing numeric IDs.
at line 640
protected void
enforceOrderBy()
Add a generic "order by" clause if the query doesn't already have one.
at line 654
Collection
pluck(string $column, string|null $key = null)
Get an array with the values of a given column.
at line 683
LengthAwarePaginator
paginate(int $perPage = null, array $columns = ['*'], string $pageName = 'page', int|null $page = null)
Paginate the given query.
at line 708
Paginator
simplePaginate(int $perPage = null, array $columns = ['*'], string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
at line 744
Model|$this
forceCreate(array $attributes)
Save a new model and return the instance. Allow mass-assignment.
at line 757
int
update(array $values)
Update a record in the database.
at line 770
int
increment(string $column, int $amount = 1, array $extra = [])
Increment a column's value by a given amount.
at line 785
int
decrement(string $column, int $amount = 1, array $extra = [])
Decrement a column's value by a given amount.
at line 798
protected array
addUpdatedAtColumn(array $values)
Add the "updated at" column to an array of values.
at line 815
mixed
delete()
Delete a record from the database.
at line 831
mixed
forceDelete()
Run the default delete function on the builder.
Since we do not apply scopes here, the row will actually be deleted.
at line 842
void
onDelete(Closure $callback)
Register a replacement for the default delete function.
at line 853
mixed
scopes(array $scopes)
Call the given local model scopes.
at line 882
Builder|Builder
applyScopes()
Apply the scopes to the Eloquent builder instance and return it.
at line 922
protected mixed
callScope(callable $scope, array $parameters = [])
Apply the given scope on the current builder instance.
at line 950
protected void
addNewWheresWithinGroup(Builder $query, int $originalWhereCount)
Nest where conditions by slicing them at the given where count.
at line 975
protected void
groupWhereSliceForScope(Builder $query, array $whereSlice)
Slice where conditions at the given offset and add them to the query as a nested condition.
at line 998
protected array
createNestedWhere(array $whereSlice, string $boolean = 'and')
Create a where array with nested where conditions.
at line 1013
$this
with(mixed $relations)
Set the relationships that should be eager loaded.
at line 1028
$this
without(mixed $relations)
Prevent the specified relations from being eager loaded.
at line 1043
Model
newModelInstance(array $attributes = [])
Create a new instance of the model being queried.
at line 1056
protected array
parseWithRelations(array $relations)
Parse a list of relations into individuals.
at line 1091
protected array
createSelectWithConstraint(string $name)
Create a constraint to select the given columns for the relation.
at line 1105
protected array
addNestedWiths(string $name, array $results)
Parse the nested relationships in a relation.
at line 1163
array
getEagerLoads()
Get the relationships being eagerly loaded.
at line 1174
$this
setEagerLoads(array $eagerLoad)
Set the relationships being eagerly loaded.
at line 1224
mixed
__call(string $method, array $parameters)
Dynamically handle calls into the query instance.
at line 1268
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls into the query instance.
at line 1292
void
__clone()
Force a clone of the underlying query builder when cloning.