Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Query/ScoutBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ public function sort($field, $direction = 'asc')
}

/**
* Apply multiple sorts to the query builder.
* Apply multiple sort directives to the underlying query builder.
*
* @param array $sorts An array of sorts to apply.
* Each element must be an array with a 'field' key and an optional 'direction' key
* (defaults to 'asc'); each directive is forwarded to sort().
*
* @param array $sorts Array of sort directives.
*/
public function applySorts($sorts)
{
Expand All @@ -129,6 +132,15 @@ public function applySorts($sorts)
}
}

/**
* Apply soft-delete visibility to the underlying Scout query builder.
*
* Sets the query to include only soft-deleted records when `$trashed` is `"only"`,
* or to include both deleted and non-deleted records when `$trashed` is `"with"`.
* Any other value is ignored (no change).
*
* @param string $trashed One of: "only" (only trashed), "with" (include trashed), or other (no-op).
*/
public function applyTrashed(string $trashed): void
{
if ($trashed === 'only') {
Expand Down
14 changes: 14 additions & 0 deletions src/Rules/Search/SearchText.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@

class SearchText extends RestRule
{
/**
* Build Laravel validation rules for a search input attribute.
*
* Returns rules that either prohibit the attribute when the resource is not model-searchable,
* or validate a nested search payload structure when searchable:
* - `<attribute>`: optionally present and must be an array.
* - `<attribute>.value`: nullable string (the search text).
* - `<attribute>.trashed`: must be one of `'with'` or `'only'`.
*
* @param string $attribute The root attribute name to validate (e.g. "search").
* @param mixed $value Unused by this rule builder; present to match the rule interface.
*
* @return array<string, array<int, mixed>> Laravel validation rules keyed by attribute path.
*/
public function buildValidationRules(string $attribute, mixed $value): array
{
if (!$this->resource->isModelSearchable()) {
Expand Down