PHP Класс Illuminate\Database\Eloquent\Builder

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$eagerLoad array The relationships that should be eager loaded.
$macros array All of the registered builder macros.
$model Model The model being queried.
$onDelete Closure A replacement for the typical delete function.
$passthru array The methods that should be returned from query builder.
$query Illuminate\Database\Query\Builder The base query builder instance.
$removedScopes array Removed global scopes.
$scopes array Applied global scopes.

Открытые методы

Метод Описание
__call ( string $method, array $parameters ) : mixed Dynamically handle calls into the query instance.
__clone ( ) : void Force a clone of the underlying query builder when cloning.
__construct ( Builder $query ) : void Create a new Eloquent query builder instance.
applyScopes ( ) : Builder | static Apply the scopes to the Eloquent builder instance and return it.
chunk ( integer $count, callable $callback ) : boolean Chunk the results of the query.
chunkById ( integer $count, callable $callback, string $column = 'id' ) : boolean Chunk the results of a query by comparing numeric IDs.
cursor ( ) : Generator Get a generator for the given query.
decrement ( string $column, integer $amount = 1, array $extra = [] ) : integer Decrement a column's value by a given amount.
delete ( ) : mixed Delete a record from the database.
doesntHave ( string $relation, string $boolean = 'and', Closure $callback = null ) : Builder | static Add a relationship count / exists condition to the query.
each ( callable $callback, integer $count = 1000 ) : boolean Execute a callback over each item while chunking.
eagerLoadRelations ( array $models ) : array Eager load the relationships for the models.
find ( mixed $id, array $columns = ['*'] ) : Model | Illuminate\Database\Eloquent\Collection | static[] | static | null Find a model by its primary key.
findMany ( array $ids, array $columns = ['*'] ) : Illuminate\Database\Eloquent\Collection Find multiple models by their primary keys.
findOrFail ( mixed $id, array $columns = ['*'] ) : Model | Illuminate\Database\Eloquent\Collection Find a model by its primary key or throw an exception.
findOrNew ( mixed $id, array $columns = ['*'] ) : Model Find a model by its primary key or return fresh model instance.
first ( array $columns = ['*'] ) : Model | static | null Execute the query and get the first result.
firstOr ( Closure | array $columns = ['*'], Closure $callback = null ) : Model | static | mixed Execute the query and get the first result or call a callback.
firstOrCreate ( array $attributes, array $values = [] ) : Model Get the first record matching the attributes or create it.
firstOrFail ( array $columns = ['*'] ) : Model | static Execute the query and get the first result or throw an exception.
firstOrNew ( array $attributes, array $values = [] ) : Model Get the first record matching the attributes or instantiate it.
forceDelete ( ) : mixed Run the default delete function on the builder.
get ( array $columns = ['*'] ) : Illuminate\Database\Eloquent\Collection | static[] Execute the query as a "select" statement.
getEagerLoads ( ) : array Get the relationships being eagerly loaded.
getMacro ( string $name ) : Closure Get the given macro by name.
getModel ( ) : Model Get the model instance being queried.
getModels ( array $columns = ['*'] ) : Model[] Get the hydrated models without eager loading.
getQuery ( ) : Builder Get the underlying query builder instance.
getRelation ( string $name ) : Illuminate\Database\Eloquent\Relations\Relation Get the relation instance for the given relation name.
has ( string $relation, string $operator = '>=', integer $count = 1, string $boolean = 'and', Closure $callback = null ) : Builder | static Add a relationship count / exists condition to the query.
increment ( string $column, integer $amount = 1, array $extra = [] ) : integer Increment a column's value by a given amount.
macro ( string $name, Closure $callback ) : void Extend the builder with a given callback.
mergeModelDefinedRelationConstraints ( Builder $relation ) : Builder | static Merge the constraints from a relation query to the current query.
onDelete ( Closure $callback ) : void Register a replacement for the default delete function.
orHas ( string $relation, string $operator = '>=', integer $count = 1 ) : Builder | static Add a relationship count / exists condition to the query with an "or".
orWhere ( string | Closure $column, string $operator = null, mixed $value = null ) : Builder | static Add an "or where" clause to the query.
orWhereHas ( string $relation, Closure $callback, string $operator = '>=', integer $count = 1 ) : Builder | static Add a relationship count / exists condition to the query with where clauses and an "or".
paginate ( integer $perPage = null, array $columns = ['*'], string $pageName = 'page', integer | null $page = null ) : Illuminate\Contracts\Pagination\LengthAwarePaginator Paginate the given query.
pluck ( string $column, string | null $key = null ) : Collection Get an array with the values of a given column.
removedScopes ( ) : array Get an array of global scopes that were removed from the query.
scopes ( array $scopes ) : mixed Add the given scopes to the current builder instance.
setEagerLoads ( array $eagerLoad ) Set the relationships being eagerly loaded.
setModel ( Model $model ) Set a model instance for the model being queried.
setQuery ( Builder $query ) Set the underlying query builder instance.
simplePaginate ( integer $perPage = null, array $columns = ['*'], string $pageName = 'page', integer | null $page = null ) : Illuminate\Contracts\Pagination\Paginator Paginate the given query into a simple paginator.
toBase ( ) : Builder Get a base query builder instance.
update ( array $values ) : integer Update a record in the database.
updateOrCreate ( array $attributes, array $values = [] ) : Model Create or update a record matching the attributes, and fill it with values.
value ( string $column ) : mixed Get a single column's value from the first result of a query.
when ( boolean $value, Closure $callback, Closure $default = null ) Apply the callback's query changes if the given "value" is true.
where ( string | Closure $column, string $operator = null, mixed $value = null, string $boolean = 'and' ) Add a basic where clause to the query.
whereDoesntHave ( string $relation, Closure $callback = null ) : Builder | static Add a relationship count / exists condition to the query with where clauses.
whereHas ( string $relation, Closure $callback = null, string $operator = '>=', integer $count = 1 ) : Builder | static Add a relationship count / exists condition to the query with where clauses.
whereKey ( mixed $id ) Add a where clause on the primary key to the query.
with ( mixed $relations ) Set the relationships that should be eager loaded.
withCount ( mixed $relations ) Add subselect queries to count the relations.
withGlobalScope ( string $identifier, Illuminate\Database\Eloquent\Scope | Closure $scope ) Register a new global scope.
without ( mixed $relations ) Prevent the specified relations from being eager loaded.
withoutGlobalScope ( Illuminate\Database\Eloquent\Scope | string $scope ) Remove a registered global scope.
withoutGlobalScopes ( array $scopes = null ) Remove all or passed registered global scopes.

Защищенные методы

Метод Описание
addHasWhere ( Builder $hasQuery, Illuminate\Database\Eloquent\Relations\Relation $relation, string $operator, integer $count, string $boolean ) : Builder | static Add the "has" condition where clause to the query.
addNestedWhereSlice ( Builder $query, array $wheres, integer $offset, integer $length = null ) : void Slice where conditions at the given offset and add them to the query as a nested condition.
addUpdatedAtColumn ( array $values ) : array Add the "updated at" column to an array of values.
callScope ( callable $scope, array $parameters = [] ) : mixed Apply the given scope on the current builder instance.
enforceOrderBy ( ) : void Add a generic "order by" clause if the query doesn't already have one.
getHasRelationQuery ( string $relation ) : Illuminate\Database\Eloquent\Relations\Relation Get the "has relation" base query instance.
hasNested ( string $relations, string $operator = '>=', integer $count = 1, string $boolean = 'and', Closure | null $callback = null ) : Builder | static Add nested relationship count / exists conditions to the query.
isNested ( string $name, string $relation ) : boolean Determine if the relationship is nested.
loadRelation ( array $models, string $name, Closure $constraints ) : array Eagerly load the relationship on a set of models.
nestWhereSlice ( array $whereSlice, string $boolean = 'and' ) : array Create a where array with nested where conditions.
nestWheresForScope ( Builder $query, integer $originalWhereCount ) : void Nest where conditions by slicing them at the given where count.
nestedRelations ( string $relation ) : array Get the deeply nested relations for a given top-level relation.
parseNestedWith ( string $name, array $results ) : array Parse the nested relationships in a relation.
parseWithRelations ( array $relations ) : array Parse a list of relations into individuals.
shouldNestWheresForScope ( Builder $query, integer $originalWhereCount ) : boolean Determine if the scope added after the given offset should be nested.
shouldRunExistsQuery ( string $operator, integer $count ) : boolean Check if we can run an "exists" query to optimize performance.
whereCountQuery ( Builder $query, string $operator = '>=', integer $count = 1, string $boolean = 'and' ) Add a sub query count clause to the query.

Описание методов

__call() публичный метод

Dynamically handle calls into the query instance.
public __call ( string $method, array $parameters ) : mixed
$method string
$parameters array
Результат mixed

__clone() публичный метод

Force a clone of the underlying query builder when cloning.
public __clone ( ) : void
Результат void

__construct() публичный метод

Create a new Eloquent query builder instance.
public __construct ( Builder $query ) : void
$query Illuminate\Database\Query\Builder
Результат void

addHasWhere() защищенный метод

Add the "has" condition where clause to the query.
protected addHasWhere ( Builder $hasQuery, Illuminate\Database\Eloquent\Relations\Relation $relation, string $operator, integer $count, string $boolean ) : Builder | static
$hasQuery Builder
$relation Illuminate\Database\Eloquent\Relations\Relation
$operator string
$count integer
$boolean string
Результат Builder | static

addNestedWhereSlice() защищенный метод

Slice where conditions at the given offset and add them to the query as a nested condition.
protected addNestedWhereSlice ( Builder $query, array $wheres, integer $offset, integer $length = null ) : void
$query Illuminate\Database\Query\Builder
$wheres array
$offset integer
$length integer
Результат void

addUpdatedAtColumn() защищенный метод

Add the "updated at" column to an array of values.
protected addUpdatedAtColumn ( array $values ) : array
$values array
Результат array

applyScopes() публичный метод

Apply the scopes to the Eloquent builder instance and return it.
public applyScopes ( ) : Builder | static
Результат Builder | static

callScope() защищенный метод

Apply the given scope on the current builder instance.
protected callScope ( callable $scope, array $parameters = [] ) : mixed
$scope callable
$parameters array
Результат mixed

chunk() публичный метод

Chunk the results of the query.
public chunk ( integer $count, callable $callback ) : boolean
$count integer
$callback callable
Результат boolean

chunkById() публичный метод

Chunk the results of a query by comparing numeric IDs.
public chunkById ( integer $count, callable $callback, string $column = 'id' ) : boolean
$count integer
$callback callable
$column string
Результат boolean

cursor() публичный метод

Get a generator for the given query.
public cursor ( ) : Generator
Результат Generator

decrement() публичный метод

Decrement a column's value by a given amount.
public decrement ( string $column, integer $amount = 1, array $extra = [] ) : integer
$column string
$amount integer
$extra array
Результат integer

delete() публичный метод

Delete a record from the database.
public delete ( ) : mixed
Результат mixed

doesntHave() публичный метод

Add a relationship count / exists condition to the query.
public doesntHave ( string $relation, string $boolean = 'and', Closure $callback = null ) : Builder | static
$relation string
$boolean string
$callback Closure
Результат Builder | static

each() публичный метод

Execute a callback over each item while chunking.
public each ( callable $callback, integer $count = 1000 ) : boolean
$callback callable
$count integer
Результат boolean

eagerLoadRelations() публичный метод

Eager load the relationships for the models.
public eagerLoadRelations ( array $models ) : array
$models array
Результат array

enforceOrderBy() защищенный метод

Add a generic "order by" clause if the query doesn't already have one.
protected enforceOrderBy ( ) : void
Результат void

find() публичный метод

Find a model by its primary key.
public find ( mixed $id, array $columns = ['*'] ) : Model | Illuminate\Database\Eloquent\Collection | static[] | static | null
$id mixed
$columns array
Результат Model | Illuminate\Database\Eloquent\Collection | static[] | static | null

findMany() публичный метод

Find multiple models by their primary keys.
public findMany ( array $ids, array $columns = ['*'] ) : Illuminate\Database\Eloquent\Collection
$ids array
$columns array
Результат Illuminate\Database\Eloquent\Collection

findOrFail() публичный метод

Find a model by its primary key or throw an exception.
public findOrFail ( mixed $id, array $columns = ['*'] ) : Model | Illuminate\Database\Eloquent\Collection
$id mixed
$columns array
Результат Model | Illuminate\Database\Eloquent\Collection

findOrNew() публичный метод

Find a model by its primary key or return fresh model instance.
public findOrNew ( mixed $id, array $columns = ['*'] ) : Model
$id mixed
$columns array
Результат Model

first() публичный метод

Execute the query and get the first result.
public first ( array $columns = ['*'] ) : Model | static | null
$columns array
Результат Model | static | null

firstOr() публичный метод

Execute the query and get the first result or call a callback.
public firstOr ( Closure | array $columns = ['*'], Closure $callback = null ) : Model | static | mixed
$columns Closure | array
$callback Closure
Результат Model | static | mixed

firstOrCreate() публичный метод

Get the first record matching the attributes or create it.
public firstOrCreate ( array $attributes, array $values = [] ) : Model
$attributes array
$values array
Результат Model

firstOrFail() публичный метод

Execute the query and get the first result or throw an exception.
public firstOrFail ( array $columns = ['*'] ) : Model | static
$columns array
Результат Model | static

firstOrNew() публичный метод

Get the first record matching the attributes or instantiate it.
public firstOrNew ( array $attributes, array $values = [] ) : Model
$attributes array
$values array
Результат Model

forceDelete() публичный метод

Run the default delete function on the builder.
public forceDelete ( ) : mixed
Результат mixed

get() публичный метод

Execute the query as a "select" statement.
public get ( array $columns = ['*'] ) : Illuminate\Database\Eloquent\Collection | static[]
$columns array
Результат Illuminate\Database\Eloquent\Collection | static[]

getEagerLoads() публичный метод

Get the relationships being eagerly loaded.
public getEagerLoads ( ) : array
Результат array

getHasRelationQuery() защищенный метод

Get the "has relation" base query instance.
protected getHasRelationQuery ( string $relation ) : Illuminate\Database\Eloquent\Relations\Relation
$relation string
Результат Illuminate\Database\Eloquent\Relations\Relation

getMacro() публичный метод

Get the given macro by name.
public getMacro ( string $name ) : Closure
$name string
Результат Closure

getModel() публичный метод

Get the model instance being queried.
public getModel ( ) : Model
Результат Model

getModels() публичный метод

Get the hydrated models without eager loading.
public getModels ( array $columns = ['*'] ) : Model[]
$columns array
Результат Model[]

getQuery() публичный метод

Get the underlying query builder instance.
public getQuery ( ) : Builder
Результат Illuminate\Database\Query\Builder

getRelation() публичный метод

Get the relation instance for the given relation name.
public getRelation ( string $name ) : Illuminate\Database\Eloquent\Relations\Relation
$name string
Результат Illuminate\Database\Eloquent\Relations\Relation

has() публичный метод

Add a relationship count / exists condition to the query.
public has ( string $relation, string $operator = '>=', integer $count = 1, string $boolean = 'and', Closure $callback = null ) : Builder | static
$relation string
$operator string
$count integer
$boolean string
$callback Closure
Результат Builder | static

hasNested() защищенный метод

Add nested relationship count / exists conditions to the query.
protected hasNested ( string $relations, string $operator = '>=', integer $count = 1, string $boolean = 'and', Closure | null $callback = null ) : Builder | static
$relations string
$operator string
$count integer
$boolean string
$callback Closure | null
Результат Builder | static

increment() публичный метод

Increment a column's value by a given amount.
public increment ( string $column, integer $amount = 1, array $extra = [] ) : integer
$column string
$amount integer
$extra array
Результат integer

isNested() защищенный метод

Determine if the relationship is nested.
protected isNested ( string $name, string $relation ) : boolean
$name string
$relation string
Результат boolean

loadRelation() защищенный метод

Eagerly load the relationship on a set of models.
protected loadRelation ( array $models, string $name, Closure $constraints ) : array
$models array
$name string
$constraints Closure
Результат array

macro() публичный метод

Extend the builder with a given callback.
public macro ( string $name, Closure $callback ) : void
$name string
$callback Closure
Результат void

mergeModelDefinedRelationConstraints() публичный метод

Merge the constraints from a relation query to the current query.
public mergeModelDefinedRelationConstraints ( Builder $relation ) : Builder | static
$relation Builder
Результат Builder | static

nestWhereSlice() защищенный метод

Create a where array with nested where conditions.
protected nestWhereSlice ( array $whereSlice, string $boolean = 'and' ) : array
$whereSlice array
$boolean string
Результат array

nestWheresForScope() защищенный метод

Nest where conditions by slicing them at the given where count.
protected nestWheresForScope ( Builder $query, integer $originalWhereCount ) : void
$query Illuminate\Database\Query\Builder
$originalWhereCount integer
Результат void

nestedRelations() защищенный метод

Get the deeply nested relations for a given top-level relation.
protected nestedRelations ( string $relation ) : array
$relation string
Результат array

onDelete() публичный метод

Register a replacement for the default delete function.
public onDelete ( Closure $callback ) : void
$callback Closure
Результат void

orHas() публичный метод

Add a relationship count / exists condition to the query with an "or".
public orHas ( string $relation, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$operator string
$count integer
Результат Builder | static

orWhere() публичный метод

Add an "or where" clause to the query.
public orWhere ( string | Closure $column, string $operator = null, mixed $value = null ) : Builder | static
$column string | Closure
$operator string
$value mixed
Результат Builder | static

orWhereHas() публичный метод

Add a relationship count / exists condition to the query with where clauses and an "or".
public orWhereHas ( string $relation, Closure $callback, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$callback Closure
$operator string
$count integer
Результат Builder | static

paginate() публичный метод

Paginate the given query.
public paginate ( integer $perPage = null, array $columns = ['*'], string $pageName = 'page', integer | null $page = null ) : Illuminate\Contracts\Pagination\LengthAwarePaginator
$perPage integer
$columns array
$pageName string
$page integer | null
Результат Illuminate\Contracts\Pagination\LengthAwarePaginator

parseNestedWith() защищенный метод

Parse the nested relationships in a relation.
protected parseNestedWith ( string $name, array $results ) : array
$name string
$results array
Результат array

parseWithRelations() защищенный метод

Parse a list of relations into individuals.
protected parseWithRelations ( array $relations ) : array
$relations array
Результат array

pluck() публичный метод

Get an array with the values of a given column.
public pluck ( string $column, string | null $key = null ) : Collection
$column string
$key string | null
Результат Illuminate\Support\Collection

removedScopes() публичный метод

Get an array of global scopes that were removed from the query.
public removedScopes ( ) : array
Результат array

scopes() публичный метод

Add the given scopes to the current builder instance.
public scopes ( array $scopes ) : mixed
$scopes array
Результат mixed

setEagerLoads() публичный метод

Set the relationships being eagerly loaded.
public setEagerLoads ( array $eagerLoad )
$eagerLoad array

setModel() публичный метод

Set a model instance for the model being queried.
public setModel ( Model $model )
$model Model

setQuery() публичный метод

Set the underlying query builder instance.
public setQuery ( Builder $query )
$query Illuminate\Database\Query\Builder

shouldNestWheresForScope() защищенный метод

Determine if the scope added after the given offset should be nested.
protected shouldNestWheresForScope ( Builder $query, integer $originalWhereCount ) : boolean
$query Illuminate\Database\Query\Builder
$originalWhereCount integer
Результат boolean

shouldRunExistsQuery() защищенный метод

Check if we can run an "exists" query to optimize performance.
protected shouldRunExistsQuery ( string $operator, integer $count ) : boolean
$operator string
$count integer
Результат boolean

simplePaginate() публичный метод

Paginate the given query into a simple paginator.
public simplePaginate ( integer $perPage = null, array $columns = ['*'], string $pageName = 'page', integer | null $page = null ) : Illuminate\Contracts\Pagination\Paginator
$perPage integer
$columns array
$pageName string
$page integer | null
Результат Illuminate\Contracts\Pagination\Paginator

toBase() публичный метод

Get a base query builder instance.
public toBase ( ) : Builder
Результат Illuminate\Database\Query\Builder

update() публичный метод

Update a record in the database.
public update ( array $values ) : integer
$values array
Результат integer

updateOrCreate() публичный метод

Create or update a record matching the attributes, and fill it with values.
public updateOrCreate ( array $attributes, array $values = [] ) : Model
$attributes array
$values array
Результат Model

value() публичный метод

Get a single column's value from the first result of a query.
public value ( string $column ) : mixed
$column string
Результат mixed

when() публичный метод

Apply the callback's query changes if the given "value" is true.
public when ( boolean $value, Closure $callback, Closure $default = null )
$value boolean
$callback Closure
$default Closure

where() публичный метод

Add a basic where clause to the query.
public where ( string | Closure $column, string $operator = null, mixed $value = null, string $boolean = 'and' )
$column string | Closure
$operator string
$value mixed
$boolean string

whereCountQuery() защищенный метод

Add a sub query count clause to the query.
protected whereCountQuery ( Builder $query, string $operator = '>=', integer $count = 1, string $boolean = 'and' )
$query Illuminate\Database\Query\Builder
$operator string
$count integer
$boolean string

whereDoesntHave() публичный метод

Add a relationship count / exists condition to the query with where clauses.
public whereDoesntHave ( string $relation, Closure $callback = null ) : Builder | static
$relation string
$callback Closure
Результат Builder | static

whereHas() публичный метод

Add a relationship count / exists condition to the query with where clauses.
public whereHas ( string $relation, Closure $callback = null, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$callback Closure
$operator string
$count integer
Результат Builder | static

whereKey() публичный метод

Add a where clause on the primary key to the query.
public whereKey ( mixed $id )
$id mixed

with() публичный метод

Set the relationships that should be eager loaded.
public with ( mixed $relations )
$relations mixed

withCount() публичный метод

Add subselect queries to count the relations.
public withCount ( mixed $relations )
$relations mixed

withGlobalScope() публичный метод

Register a new global scope.
public withGlobalScope ( string $identifier, Illuminate\Database\Eloquent\Scope | Closure $scope )
$identifier string
$scope Illuminate\Database\Eloquent\Scope | Closure

without() публичный метод

Prevent the specified relations from being eager loaded.
public without ( mixed $relations )
$relations mixed

withoutGlobalScope() публичный метод

Remove a registered global scope.
public withoutGlobalScope ( Illuminate\Database\Eloquent\Scope | string $scope )
$scope Illuminate\Database\Eloquent\Scope | string

withoutGlobalScopes() публичный метод

Remove all or passed registered global scopes.
public withoutGlobalScopes ( array $scopes = null )
$scopes array

Описание свойств

$eagerLoad защищенное свойство

The relationships that should be eager loaded.
protected array $eagerLoad
Результат array

$macros защищенное свойство

All of the registered builder macros.
protected array $macros
Результат array

$model защищенное свойство

The model being queried.
protected Model,Illuminate\Database\Eloquent $model
Результат Model

$onDelete защищенное свойство

A replacement for the typical delete function.
protected Closure $onDelete
Результат Closure

$passthru защищенное свойство

The methods that should be returned from query builder.
protected array $passthru
Результат array

$query защищенное свойство

The base query builder instance.
protected Builder,Illuminate\Database\Query $query
Результат Illuminate\Database\Query\Builder

$removedScopes защищенное свойство

Removed global scopes.
protected array $removedScopes
Результат array

$scopes защищенное свойство

Applied global scopes.
protected array $scopes
Результат array