trait BuildsQueries mixin TKey,

Traits

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $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.

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
chunkByIdDesc(int $count, callable $callback, string|null $column = null, string|null $alias = null)

Chunk the results of a query by comparing IDs in descending order.

bool
orderedChunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)

Chunk the results of a query by comparing IDs in a given order.

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.

lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)

Query lazily, by chunking the results of a query by comparing IDs.

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.

orderedLazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)

Query lazily, by chunking the results of a query by comparing IDs in a given order.

mixed
getLastIdFromChunk(mixed $result, string $alias)

Get the ID of the last result of a chunk to continue paging from.

mixed
getNextPageIdFromChunk(mixed $result, string $column, string $alias)

Prepare the last chunk ID for comparison with the paging column.

string
getPagingAttribute(Model $model, string $column)

Get the model attribute behind a qualified paging column.

null|TValue
first(array|string $columns = ['*'])

Execute the query and get the first result.

TValue
firstOrFail(array|string $columns = ['*'], string|null $message = null)

Execute the query and get the first result or throw an exception.

TValue
sole(array|string $columns = ['*'])

Execute the query and get the first result if it's the sole matching record.

paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)

Paginate the given query using a cursor paginator.

getBuilderForCursorPage()

Get the builder that owns cursor binding and page execution.

mixed
getCursorParameterBinding(Cursor $cursor, string $parameter)

Get a cursor parameter for database binding.

string
getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)

Get the original column name of the given column, without any aliasing.

bool
isCursorExpression(Builder $query, string $parameter, string $original)

Determine whether the resolved cursor column is a declared SQL expression.

paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)

Create a new length-aware paginator instance.

simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)

Create a new simple paginator instance.

cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)

Create a new cursor paginator instance.

tap(callable $callback)

Pass the query to a given callback and then return it.

TReturn is null|TReturn)
pipe(callable $callback)

Pass the query to a given callback and return the result.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 45
bool chunk(int $count, callable $callback)

Chunk the results of the query.

Parameters

int $count
callable $callback

Return Value

bool

at line 101
Collection chunkMap(callable $callback, int $count = 1000)

Run a map over each item while chunking.

Parameters

callable $callback
int $count

Return Value

Collection

at line 119
bool each(callable $callback, int $count = 1000)

Execute a callback over each item while chunking.

Parameters

callable $callback
int $count

Return Value

bool

at line 137
bool chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null)

Chunk the results of a query by comparing IDs.

Parameters

int $count
callable $callback
string|null $column
string|null $alias

Return Value

bool

at line 147
bool chunkByIdDesc(int $count, callable $callback, string|null $column = null, string|null $alias = null)

Chunk the results of a query by comparing IDs in descending order.

Parameters

int $count
callable $callback
string|null $column
string|null $alias

Return Value

bool

at line 157
bool orderedChunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)

Chunk the results of a query by comparing IDs in a given order.

Parameters

int $count
callable $callback
string|null $column
string|null $alias
SortDirection|bool $descending

Return Value

bool

at line 230
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.

Parameters

callable $callback
int $count
string|null $column
string|null $alias

Return Value

bool

at line 248
LazyCollection lazy(int $chunkSize = 1000)

Query lazily, by chunks of the given size.

Parameters

int $chunkSize

Return Value

LazyCollection

at line 301
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.

Parameters

int $chunkSize
string|null $column
string|null $alias

Return Value

LazyCollection

at line 311
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.

Parameters

int $chunkSize
string|null $column
string|null $alias

Return Value

LazyCollection

at line 324
protected LazyCollection orderedLazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null, SortDirection|bool $descending = false)

Query lazily, by chunking the results of a query by comparing IDs in a given order.

Parameters

int $chunkSize
string|null $column
string|null $alias
SortDirection|bool $descending

Return Value

LazyCollection

Exceptions

InvalidArgumentException
RuntimeException

at line 392
protected mixed getLastIdFromChunk(mixed $result, string $alias)

Get the ID of the last result of a chunk to continue paging from.

Parameters

mixed $result
string $alias

Return Value

mixed

at line 407
protected mixed getNextPageIdFromChunk(mixed $result, string $column, string $alias)

Prepare the last chunk ID for comparison with the paging column.

Parameters

mixed $result
string $column
string $alias

Return Value

mixed

at line 425
protected string getPagingAttribute(Model $model, string $column)

Get the model attribute behind a qualified paging column.

Parameters

Model $model
string $column

Return Value

string

at line 447
null|TValue first(array|string $columns = ['*'])

Execute the query and get the first result.

Parameters

array|string $columns

Return Value

null|TValue

at line 459
TValue firstOrFail(array|string $columns = ['*'], string|null $message = null)

Execute the query and get the first result or throw an exception.

Parameters

array|string $columns
string|null $message

Return Value

TValue

Exceptions

RecordNotFoundException

at line 479
TValue sole(array|string $columns = ['*'])

Execute the query and get the first result if it's the sole matching record.

Parameters

array|string $columns

Return Value

TValue

Exceptions

RecordsNotFoundException
MultipleRecordsFoundException

at line 499
protected CursorPaginator paginateUsingCursor(int $perPage, array|string $columns = ['*'], string $cursorName = 'cursor', Cursor|string|null $cursor = null)

Paginate the given query using a cursor paginator.

Parameters

int $perPage
array|string $columns
string $cursorName
Cursor|string|null $cursor

Return Value

CursorPaginator

at line 561
protected BuildsQueries getBuilderForCursorPage()

Get the builder that owns cursor binding and page execution.

Return Value

BuildsQueries

at line 569
protected mixed getCursorParameterBinding(Cursor $cursor, string $parameter)

Get a cursor parameter for database binding.

Parameters

Cursor $cursor
string $parameter

Return Value

mixed

at line 579
protected string getOriginalColumnNameForCursorPagination(Builder|Builder $builder, string $parameter)

Get the original column name of the given column, without any aliasing.

Parameters

Builder|Builder $builder
string $parameter

Return Value

string

at line 604
protected bool isCursorExpression(Builder $query, string $parameter, string $original)

Determine whether the resolved cursor column is a declared SQL expression.

Parameters

Builder $query
string $parameter
string $original

Return Value

bool

at line 629
protected LengthAwarePaginator paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)

Create a new length-aware paginator instance.

Parameters

Collection $items
int $total
int $perPage
int $currentPage
array $options

Return Value

LengthAwarePaginator

at line 639
protected Paginator simplePaginator(Collection $items, int $perPage, int $currentPage, array $options)

Create a new simple paginator instance.

Parameters

Collection $items
int $perPage
int $currentPage
array $options

Return Value

Paginator

at line 649
protected CursorPaginator cursorPaginator(Collection $items, int $perPage, Cursor|null $cursor, array $options)

Create a new cursor paginator instance.

Parameters

Collection $items
int $perPage
Cursor|null $cursor
array $options

Return Value

CursorPaginator

at line 662
BuildsQueries tap(callable $callback)

Pass the query to a given callback and then return it.

Parameters

callable $callback

Return Value

BuildsQueries

at line 677
TReturn is null|TReturn) pipe(callable $callback)

Pass the query to a given callback and return the result.

Parameters

callable $callback

Return Value

TReturn is null|TReturn)