Builder
class Builder
Fluent search query builder for searchable models.
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| SearchableInterface&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<int, array{field: string, operator: string, value: 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 constraint to the search query.
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 prepared engine that should handle the query.
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 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 115
__construct(Model $model, string $query, Closure|null $callback = null, bool $softDelete = false)
Create a new search builder instance.
at line 140
Builder
within(string $index)
Specify a custom index for search or filtered deletion.
at line 152
Builder
where(string $field, mixed $operator, mixed $value = null)
Add a constraint to the search query.
at line 172
Builder
whereIn(string $field, array|Arrayable $values)
Add a "where in" constraint to the search query.
at line 189
Builder
whereNotIn(string $field, array|Arrayable $values)
Add a "where not in" constraint to the search query.
at line 205
Builder
withTrashed()
Include soft deleted records in the results.
at line 220
Builder
onlyTrashed()
Include only soft deleted records in the results.
at line 236
Builder
take(int $limit)
Set the "limit" for the search query.
at line 248
Builder
orderBy(string $column, string $direction = 'asc')
Add an "order" for the search query.
at line 263
Builder
orderByDesc(string $column)
Add a descending "order by" clause to the search query.
at line 273
Builder
latest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (descending).
at line 285
Builder
oldest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (ascending).
at line 298
Builder
options(array $options)
Set extra options for the search query.
at line 310
Builder
query(callable $callback)
Set the callback that should have an opportunity to modify the database query.
at line 320
mixed
raw()
Get the raw results of the search.
at line 331
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 341
Collection
keys()
Get the keys of search results.
at line 351
Model|null
first()
Get the first result from the search.
at line 361
Collection
get()
Get the results of the search.
at line 371
LazyCollection
cursor()
Get the results of the search as a lazy collection.
at line 379
Paginator
simplePaginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
at line 432
LengthAwarePaginator
paginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a length-aware paginator.
at line 484
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 529
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 576
protected int
getTotalCount(mixed $results)
Get the total number of results from the Scout engine, or fallback to query builder.
at line 605
mixed
applyAfterRawSearchCallback(mixed $results)
Invoke the "after raw search" callback.
at line 617
protected Engine
preparedEngine()
Get the prepared engine that should handle the query.
at line 629
protected Engine
engine()
Get the engine that should handle the query.
at line 637
string
modelConnectionType()
Get the connection type for the underlying model.
at line 648
static void
flushState()
Flush all static state.