Builder
Implements
Uses
Properties
$eagerLoad array
The relationships that should be eager loaded.
$macros array
All of the globally registered builder macros.
$localMacros array
All of the locally registered builder macros.
$propertyPassthru string[]
The properties that should be returned from query builder.
$passthru string[]
The methods that should be returned from query builder.
$scopes array
Applied global scopes.
$removedScopes array
Removed global scopes.
Methods
__construct ( Builder $query ) : void
Create a new Eloquent query builder instance.
Parameters
- $query Builder
make ( array $attributes ) : Model |static
Create and return an un-saved model instance.
Parameters
- $attributes array
withGlobalScope ( $identifier , $scope ) : $this
Register a new global scope.
Parameters
withoutGlobalScope ( $scope ) : $this
Remove a registered global scope.
Parameters
- $scope Scope |string
withoutGlobalScopes ( array $scopes ) : $this
Remove all or passed registered global scopes.
Parameters
- $scopes array|null
removedScopes ( ) : array
Get an array of global scopes that were removed from the query.
whereKey ( $id ) : $this
Add a where clause on the primary key to the query.
Parameters
- $id mixed
whereKeyNot ( $id ) : $this
Add a where clause on the primary key to the query.
Parameters
- $id mixed
where ( $column , $operator , $value , $boolean ) : $this
Add a basic where clause to the query.
Parameters
- $column Closure |string|array|Expression
- $operator mixed
- $value mixed
- $boolean string
firstWhere ( $column , $operator , $value , $boolean ) : Model |static|null
Add a basic where clause to the query, and return the first result.
Parameters
- $column Closure |string|array|Expression
- $operator mixed
- $value mixed
- $boolean string
orWhere ( $column , $operator , $value ) : $this
Add an "or where" clause to the query.
Parameters
- $column Closure |array|string|Expression
- $operator mixed
- $value mixed
whereNot ( $column , $operator , $value , $boolean ) : $this
Add a basic "where not" clause to the query.
Parameters
- $column Closure |string|array|Expression
- $operator mixed
- $value mixed
- $boolean string
orWhereNot ( $column , $operator , $value ) : $this
Add an "or where not" clause to the query.
Parameters
- $column Closure |array|string|Expression
- $operator mixed
- $value mixed
latest ( $column ) : $this
Add an "order by" clause for a timestamp to the query.
Parameters
- $column string|Expression
oldest ( $column ) : $this
Add an "order by" clause for a timestamp to the query.
Parameters
- $column string|Expression
hydrate ( array $items ) : Illuminate\...\Collection
Create a collection of models from plain arrays.
Parameters
- $items array
fromQuery ( $query , $bindings ) : Illuminate\...\Collection
Create a collection of models from a raw query.
Parameters
- $query string
- $bindings array
find ( $id , $columns ) : Model |Illuminate\...\Collection|static[]|static|null
Find a model by its primary key.
Parameters
- $id mixed
- $columns array|string
findMany ( $ids , $columns ) : Illuminate\...\Collection
Find multiple models by their primary keys.
Parameters
- $ids Illuminate\...\Arrayable|array
- $columns array|string
findOrFail ( $id , $columns ) : Model |Illuminate\...\Collection|static|static[]
Find a model by its primary key or throw an exception.
Parameters
- $id mixed
- $columns array|string
findOrNew ( $id , $columns ) : Model |static
Find a model by its primary key or return fresh model instance.
Parameters
- $id mixed
- $columns array|string
findOr ( $id , $columns , Closure $callback ) : Model |Illuminate\...\Collection|static[]|static|mixed
Find a model by its primary key or call a callback.
Parameters
firstOrNew ( array $attributes , array $values ) : Model |static
Get the first record matching the attributes or instantiate it.
Parameters
- $attributes array
- $values array
firstOrCreate ( array $attributes , array $values ) : Model |static
Get the first record matching the attributes or create it.
Parameters
- $attributes array
- $values array
updateOrCreate ( array $attributes , array $values ) : Model |static
Create or update a record matching the attributes, and fill it with values.
Parameters
- $attributes array
- $values array
firstOrFail ( $columns ) : Model |static
Execute the query and get the first result or throw an exception.
Parameters
- $columns array|string
firstOr ( $columns , Closure $callback ) : Model |static|mixed
Execute the query and get the first result or call a callback.
Parameters
sole ( $columns ) : Model
Execute the query and get the first result if it's the sole matching record.
Parameters
- $columns array|string
value ( $column ) : mixed
Get a single column's value from the first result of a query.
Parameters
- $column string|Expression
soleValue ( $column ) : mixed
Get a single column's value from the first result of a query if it's the sole matching record.
Parameters
- $column string|Expression
valueOrFail ( $column ) : mixed
Get a single column's value from the first result of the query or throw an exception.
Parameters
- $column string|Expression
get ( $columns ) : Illuminate\...\Collection|static[]
Execute the query as a "select" statement.
Parameters
- $columns array|string
getModels ( $columns ) : Illuminate\...\Model[]|static[]
Get the hydrated models without eager loading.
Parameters
- $columns array|string
eagerLoadRelations ( array $models ) : array
Eager load the relationships for the models.
Parameters
- $models array
eagerLoadRelation ( array $models , $name , Closure $constraints ) : array
Eagerly load the relationship on a set of models.
Parameters
- $models array
- $name string
- $constraints Closure
getRelation ( $name ) : Relation
Get the relation instance for the given relation name.
Parameters
- $name string
relationsNestedUnder ( $relation ) : array
Get the deeply nested relations for a given top-level relation.
Parameters
- $relation string
isNestedUnder ( $relation , $name ) : bool
Determine if the relationship is nested.
Parameters
- $relation string
- $name string
cursor ( ) : Illuminate\...\LazyCollection
Get a lazy collection for the given query.
enforceOrderBy ( ) : void
Add a generic "order by" clause if the query doesn't already have one.
pluck ( $column , $key ) : Illuminate\...\Collection
Get a collection with the values of a given column.
Parameters
- $column string|Expression
- $key string|null
paginate ( $perPage , $columns , $pageName , $page , $total ) : LengthAwarePaginator
Paginate the given query.
Parameters
simplePaginate ( $perPage , $columns , $pageName , $page ) : Paginator
Paginate the given query into a simple paginator.
Parameters
- $perPage int|null
- $columns array|string
- $pageName string
- $page int|null
cursorPaginate ( $perPage , $columns , $cursorName , $cursor ) : CursorPaginator
Paginate the given query into a cursor paginator.
Parameters
- $perPage int|null
- $columns array|string
- $cursorName string
- $cursor Cursor |string|null
ensureOrderForCursorPagination ( $shouldReverse ) : Illuminate\...\Collection
Ensure the proper order by required for cursor pagination.
Parameters
- $shouldReverse bool
create ( array $attributes ) : Model |$this
Save a new model and return the instance.
Parameters
- $attributes array
forceCreate ( array $attributes ) : Model |$this
Save a new model and return the instance. Allow mass-assignment.
Parameters
- $attributes array
forceCreateQuietly ( array $attributes ) : Model |$this
Save a new model instance with mass assignment without raising model events.
Parameters
- $attributes array
update ( array $values ) : int
Update records in the database.
Parameters
- $values array
upsert ( array $values , $uniqueBy , $update ) : int
Insert new records or update the existing ones.
Parameters
- $values array
- $uniqueBy array|string
- $update array|null
touch ( $column ) : int|false
Update the column's update timestamp.
Parameters
- $column string|null
increment ( $column , $amount , array $extra ) : int
Increment a column's value by a given amount.
Parameters
- $column string|Expression
- $amount float|int
- $extra array
decrement ( $column , $amount , array $extra ) : int
Decrement a column's value by a given amount.
Parameters
- $column string|Expression
- $amount float|int
- $extra array
addUpdatedAtColumn ( array $values ) : array
Add the "updated at" column to an array of values.
Parameters
- $values array
addUniqueIdsToUpsertValues ( array $values ) : array
Add unique IDs to the inserted values.
Parameters
- $values array
addTimestampsToUpsertValues ( array $values ) : array
Add timestamps to the inserted values.
Parameters
- $values array
addUpdatedAtToUpsertColumns ( array $update ) : array
Add the "updated at" column to the updated columns.
Parameters
- $update array
delete ( ) : mixed
Delete records from the database.
forceDelete ( ) : mixed
Run the default delete function on the builder.
onDelete ( Closure $callback ) : void
Register a replacement for the default delete function.
Parameters
- $callback Closure
hasNamedScope ( $scope ) : bool
Determine if the given model has a scope.
Parameters
- $scope string
scopes ( $scopes ) : static|mixed
Call the given local model scopes.
Parameters
- $scopes array|string
applyScopes ( ) : static
Apply the scopes to the Eloquent builder instance and return it.
callScope ( callable $scope , array $parameters ) : mixed
Apply the given scope on the current builder instance.
Parameters
- $scope callable
- $parameters array
callNamedScope ( $scope , array $parameters ) : mixed
Apply the given named scope on the current builder instance.
Parameters
- $scope string
- $parameters array
addNewWheresWithinGroup ( Builder $query , $originalWhereCount ) : void
Nest where conditions by slicing them at the given where count.
Parameters
- $query Builder
- $originalWhereCount int
groupWhereSliceForScope ( Builder $query , $whereSlice ) : void
Slice where conditions at the given offset and add them to the query as a nested condition.
Parameters
- $query Builder
- $whereSlice array
createNestedWhere ( $whereSlice , $boolean ) : array
Create a where array with nested where conditions.
Parameters
- $whereSlice array
- $boolean string
with ( $relations , $callback ) : $this
Set the relationships that should be eager loaded.
Parameters
- $relations string|array
- $callback string|Closure |null
without ( $relations ) : $this
Prevent the specified relations from being eager loaded.
Parameters
- $relations mixed
withOnly ( $relations ) : $this
Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
Parameters
- $relations mixed
newModelInstance ( $attributes ) : Model |static
Create a new instance of the model being queried.
Parameters
- $attributes array
parseWithRelations ( array $relations ) : array
Parse a list of relations into individuals.
Parameters
- $relations array
prepareNestedWithRelationships ( $relations , $prefix ) : array
Prepare nested with relationships.
Parameters
- $relations array
- $prefix string
combineConstraints ( array $constraints ) : Closure
Combine an array of constraints into a single constraint.
Parameters
- $constraints array
parseNameAndAttributeSelectionConstraint ( $name ) : array
Parse the attribute select constraints from the name.
Parameters
- $name string
createSelectWithConstraint ( $name ) : array
Create a constraint to select the given columns for the relation.
Parameters
- $name string
addNestedWiths ( $name , $results ) : array
Parse the nested relationships in a relation.
Parameters
- $name string
- $results array
withCasts ( $casts ) : $this
Apply query-time casts to the model instance.
Parameters
- $casts array
setQuery ( $query ) : $this
Set the underlying query builder instance.
Parameters
- $query Builder
getEagerLoads ( ) : array
Get the relationships being eagerly loaded.
setEagerLoads ( array $eagerLoad ) : $this
Set the relationships being eagerly loaded.
Parameters
- $eagerLoad array
withoutEagerLoad ( array $relations ) : $this
Indicate that the given relationships should not be eagerly loaded.
Parameters
- $relations array
withoutEagerLoads ( ) : $this
Flush the relationships being eagerly loaded.
defaultKeyName ( ) : string
Get the default key name of the table.
setModel ( Model $model ) : $this
Set a model instance for the model being queried.
Parameters
- $model Model
qualifyColumn ( $column ) : string
Qualify the given column name by the model's table.
Parameters
- $column string|Expression
qualifyColumns ( $columns ) : array
Qualify the given columns with the model's table.
Parameters
- $columns array|Expression
hasMacro ( $name ) : bool
Checks if a macro is registered.
Parameters
- $name string
getGlobalMacro ( $name ) : Closure
Get the given global macro by name.
Parameters
- $name string
hasGlobalMacro ( $name ) : bool
Checks if a global macro is registered.
Parameters
- $name string
__get ( $key ) : mixed
Dynamically access builder proxies.
Parameters
- $key string
__call ( $method , $parameters ) : mixed
Dynamically handle calls into the query instance.
Parameters
- $method string
- $parameters array
__callStatic ( $method , $parameters ) : mixed
Dynamically handle calls into the query instance.
Parameters
- $method string
- $parameters array
registerMixin ( $mixin , $replace ) : void
Register the given mixin with the builder.
Parameters
- $mixin string
- $replace bool
clone ( ) : static
Clone the Eloquent query builder.
__clone ( ) : void
Force a clone of the underlying query builder when cloning.