Skip to content

Commit 1163f71

Browse files
authored
🐛 search text with null operator (#183)
1 parent aab3ab5 commit 1163f71

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/Rules/Search/SearchText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function buildValidationRules(string $attribute, mixed $value): array
1616

1717
return [
1818
$attribute => ['sometimes', 'array'],
19-
$attribute.'.value' => ['string'],
19+
$attribute.'.value' => ['nullable', 'string'],
2020
];
2121
}
2222
}

tests/Feature/Controllers/SearchScoutOperationsTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,54 @@ public function test_getting_a_list_of_resources_with_scout(): void
329329
new ModelResource()
330330
);
331331
}
332+
333+
public function test_getting_a_list_of_resources_with_empty_scout(): void
334+
{
335+
ModelFactory::new()->count(2)->create();
336+
337+
Gate::policy(Model::class, GreenPolicy::class);
338+
339+
$response = $this->post(
340+
'/api/searchable-models/search',
341+
[
342+
'search' => [
343+
'text' => [
344+
'value' => '',
345+
],
346+
],
347+
],
348+
['Accept' => 'application/json']
349+
);
350+
351+
$this->assertResourcePaginated(
352+
$response,
353+
[],
354+
new ModelResource()
355+
);
356+
}
357+
358+
public function test_getting_a_list_of_resources_with_null_scout(): void
359+
{
360+
ModelFactory::new()->count(2)->create();
361+
362+
Gate::policy(Model::class, GreenPolicy::class);
363+
364+
$response = $this->post(
365+
'/api/searchable-models/search',
366+
[
367+
'search' => [
368+
'text' => [
369+
'value' => null,
370+
],
371+
],
372+
],
373+
['Accept' => 'application/json']
374+
);
375+
376+
$this->assertResourcePaginated(
377+
$response,
378+
[],
379+
new ModelResource()
380+
);
381+
}
332382
}

0 commit comments

Comments
 (0)