Skip to content

Commit d6ce084

Browse files
📝 Add docstrings to feature/scout-trashed
Docstrings generation was requested by @GautierDele. * #186 (comment) The following files were modified: * `src/Query/ScoutBuilder.php` * `src/Rules/Search/SearchText.php`
1 parent 9284c49 commit d6ce084

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Query/ScoutBuilder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ public function sort($field, $direction = 'asc')
118118
}
119119

120120
/**
121-
* Apply multiple sorts to the query builder.
121+
* Apply multiple sort directives to the underlying query builder.
122122
*
123-
* @param array $sorts An array of sorts to apply.
123+
* Each element must be an array with a 'field' key and an optional 'direction' key
124+
* (defaults to 'asc'); each directive is forwarded to sort().
125+
*
126+
* @param array $sorts Array of sort directives.
124127
*/
125128
public function applySorts($sorts)
126129
{
@@ -129,6 +132,15 @@ public function applySorts($sorts)
129132
}
130133
}
131134

135+
/**
136+
* Apply soft-delete visibility to the underlying Scout query builder.
137+
*
138+
* Sets the query to include only soft-deleted records when `$trashed` is `"only"`,
139+
* or to include both deleted and non-deleted records when `$trashed` is `"with"`.
140+
* Any other value is ignored (no change).
141+
*
142+
* @param string $trashed One of: "only" (only trashed), "with" (include trashed), or other (no-op).
143+
*/
132144
public function applyTrashed(string $trashed): void
133145
{
134146
if ($trashed === 'only') {

src/Rules/Search/SearchText.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

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

0 commit comments

Comments
 (0)