On this page
BuildsQueries
trait BuildsQueries (View source)
Traits
Methods
$this|TWhenReturnType | when($value = null, callable $callback = null, callable $default = null) Apply the callback if the given "value" is (or resolves to) truthy. |
from Conditionable |
$this|TUnlessReturnType | unless($value = null, callable $callback = null, callable $default = null) Apply the callback if the given "value" is (or resolves to) falsy. |
from Conditionable |
bool | chunk(int $count, callable $callback) Chunk the results of the query. |
|
Collection | chunkMap(callable $callback, int $count = 1000) Run a map over each item while chunking. |
|
bool | each(callable $callback, int $count = 1000) Execute a callback over each item while chunking. |
|
bool | chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null) Chunk the results of a query by comparing IDs. |
|
bool | eachById(callable $callback, int $count = 1000, string|null $column = null, string|null $alias = null) Execute a callback over each item while chunking by ID. |
|
LazyCollection | lazy(int $chunkSize = 1000) Query lazily, by chunks of the given size. |
|
LazyCollection | lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null) Query lazily, by chunking the results of a query by comparing IDs. |
|
LazyCollection | lazyByIdDesc(int $chunkSize = 1000, string|null $column = null, string|null $alias = null) Query lazily, by chunking the results of a query by comparing IDs in descending order. |
|
LazyCollection | orderedLazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null, bool $descending = false) Query lazily, by chunking the results of a query by comparing IDs in a given order. |
|
Model|object|BuildsQueries|null | first(array|string $columns = ['*']) Execute the query and get the first result. |
|
Model|object|BuildsQueries|null | sole(array|string $columns = ['*']) Execute the query and get the first result if it's the sole matching record. |
|
CursorPaginator | paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null) Paginate the given query using a cursor paginator. |
|
string | getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter) Get the original column name of the given column, without any aliasing. |
|
LengthAwarePaginator | paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options) Create a new length-aware paginator instance. |
|
Paginator | simplePaginator(Collection $items, int $perPage, int $currentPage, array $options) Create a new simple paginator instance. |
|
CursorPaginator | cursorPaginator(Collection $items, int $perPage, Cursor $cursor, array $options) Create a new cursor paginator instance. |
|
$this | tap(callable $callback) Pass the query to a given callback. |
Details
$this|TWhenReturnType when($value = null, callable $callback = null, callable $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
$this|TUnlessReturnType unless($value = null, callable $callback = null, callable $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
bool chunk(int $count, callable $callback)
Chunk the results of the query.
Collection chunkMap(callable $callback, int $count = 1000)
Run a map over each item while chunking.
bool each(callable $callback, int $count = 1000)
Execute a callback over each item while chunking.
bool chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null)
Chunk the results of a query by comparing IDs.
bool eachById(callable $callback, int $count = 1000, string|null $column = null, string|null $alias = null)
Execute a callback over each item while chunking by ID.
LazyCollection lazy(int $chunkSize = 1000)
Query lazily, by chunks of the given size.
LazyCollection lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
Query lazily, by chunking the results of a query by comparing IDs.
LazyCollection lazyByIdDesc(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
Query lazily, by chunking the results of a query by comparing IDs in descending order.
protected LazyCollection orderedLazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null, bool $descending = false)
Query lazily, by chunking the results of a query by comparing IDs in a given order.
Model|object|BuildsQueries|null first(array|string $columns = ['*'])
Execute the query and get the first result.
Model|object|BuildsQueries|null sole(array|string $columns = ['*'])
Execute the query and get the first result if it's the sole matching record.
protected CursorPaginator paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)
Paginate the given query using a cursor paginator.
protected string getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)
Get the original column name of the given column, without any aliasing.
protected LengthAwarePaginator paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
Create a new length-aware paginator instance.
protected Paginator simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)
Create a new simple paginator instance.
protected CursorPaginator cursorPaginator(Collection $items, int $perPage, Cursor $cursor, array $options)
Create a new cursor paginator instance.
$this tap(callable $callback)
Pass the query to a given callback.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Database/Concerns/BuildsQueries.html