Builder
class Builder
Fluent search query builder for searchable models.
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| TModel | $model | The model instance. |
|
| string | $query | The query expression. |
|
| Closure|null | $callback | Optional callback before search execution. |
|
| Closure|null | $queryCallback | Optional callback before model query execution. |
|
| Closure|null | $afterRawSearchCallback | Optional callback after raw search. |
|
| string|null | $index | The custom index specified for the search. |
|
| array<string, mixed> | $wheres | The "where" constraints added to the query. |
|
| array<string, mixed[]> | $whereIns | The "where in" constraints added to the query. |
|
| array<string, mixed[]> | $whereNotIns | The "where not in" constraints added to the query. |
|
| int|null | $limit | The "limit" that should be applied to the search. |
|
| array<array{column: string, direction: string}> | $orders | The "order" that should be applied to the search. |
|
| array<string, mixed> | $options | Extra options that should be applied to the search. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Call the given Closure with this instance then return the instance.
Create a new search builder instance.
Add a "where not in" constraint to the search query.
Include soft deleted records in the results.
Include only soft deleted records in the results.
Add a descending "order by" clause to the search query.
Add an "order by" clause for a timestamp to the query (descending).
Add an "order by" clause for a timestamp to the query (ascending).
Set the callback that should have an opportunity to modify the database query.
Get the raw results of the search.
Set the callback that should have an opportunity to inspect and modify the raw result returned by the search engine.
Get the keys of search results.
Get the results of the search.
Get the results of the search as a lazy collection.
Paginate the given query into a simple paginator.
Paginate the given query into a length-aware paginator.
Paginate the given query into a length-aware paginator with raw data.
Paginate the given query into a simple paginator with raw data.
Get the total number of results from the Scout engine, or fallback to query builder.
Invoke the "after raw search" callback.
Get the connection type for the underlying model.
Flush all static state.
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.
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.
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
Tappable at line 15
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 114
__construct(Model $model, string $query, Closure|null $callback = null, bool $softDelete = false)
Create a new search builder instance.
at line 134
Builder
within(string $index)
Specify a custom index to perform this search on.
at line 146
Builder
where(string $field, mixed $value)
Add a constraint to the search query.
at line 159
Builder
whereIn(string $field, array|Arrayable $values)
Add a "where in" constraint to the search query.
at line 176
Builder
whereNotIn(string $field, array|Arrayable $values)
Add a "where not in" constraint to the search query.
at line 192
Builder
withTrashed()
Include soft deleted records in the results.
at line 204
Builder
onlyTrashed()
Include only soft deleted records in the results.
at line 216
Builder
take(int $limit)
Set the "limit" for the search query.
at line 228
Builder
orderBy(string $column, string $direction = 'asc')
Add an "order" for the search query.
at line 243
Builder
orderByDesc(string $column)
Add a descending "order by" clause to the search query.
at line 253
Builder
latest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (descending).
at line 265
Builder
oldest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (ascending).
at line 278
Builder
options(array $options)
Set extra options for the search query.
at line 290
Builder
query(callable $callback)
Set the callback that should have an opportunity to modify the database query.
at line 300
mixed
raw()
Get the raw results of the search.
at line 311
Builder
withRawResults(callable $callback)
Set the callback that should have an opportunity to inspect and modify the raw result returned by the search engine.
at line 321
Collection
keys()
Get the keys of search results.
at line 331
Model|null
first()
Get the first result from the search.
at line 341
Collection
get()
Get the results of the search.
at line 351
LazyCollection
cursor()
Get the results of the search as a lazy collection.
at line 359
Paginator
simplePaginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
at line 397
LengthAwarePaginator
paginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a length-aware paginator.
at line 439
LengthAwarePaginator
paginateRaw(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a length-aware paginator with raw data.
at line 468
Paginator
simplePaginateRaw(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator with raw data.
at line 494
protected int
getTotalCount(mixed $results)
Get the total number of results from the Scout engine, or fallback to query builder.
at line 523
mixed
applyAfterRawSearchCallback(mixed $results)
Invoke the "after raw search" callback.
at line 535
protected Engine
engine()
Get the engine that should handle the query.
at line 543
string
modelConnectionType()
Get the connection type for the underlying model.
at line 554
static void
flushState()
Flush all static state.