Skip to content

Commit 8191499

Browse files
authored
Merge pull request #62 from Lomkit/feature/allow-null-values-on-fields
Feature/allow null values on fields
2 parents e23e241 + d8914e7 commit 8191499

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Rules/SearchRules.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function filtersRules(\Lomkit\Rest\Http\Resource $resource, string $prefi
120120
'string',
121121
],
122122
$prefix.'.*.value' => [
123+
"exclude_if:$prefix.*.value,null",
123124
"required_without:$prefix.*.nested",
124125
],
125126
$prefix.'.*.type' => [

tests/Feature/Controllers/SearchFilteringOperationsTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ public function test_getting_a_list_of_resources_filtered_by_model_field_using_d
6262
);
6363
}
6464

65+
public function test_getting_a_list_of_resources_filtered_by_model_field_with_null_value(): void
66+
{
67+
$matchingModel = ModelFactory::new()->create(['string' => null])->fresh();
68+
ModelFactory::new()->create(['string' => 'not match'])->fresh();
69+
70+
Gate::policy(Model::class, GreenPolicy::class);
71+
72+
$response = $this->post(
73+
'/api/models/search',
74+
[
75+
'search' => [
76+
'filters' => [
77+
['field' => 'string', 'value' => null],
78+
],
79+
],
80+
],
81+
['Accept' => 'application/json']
82+
);
83+
84+
$this->assertResourcePaginated(
85+
$response,
86+
[$matchingModel],
87+
new ModelResource()
88+
);
89+
}
90+
6591
public function test_getting_a_list_of_resources_filtered_by_model_field_using_in_operator(): void
6692
{
6793
$matchingModel = ModelFactory::new()->create(['name' => 'match'])->fresh();

0 commit comments

Comments
 (0)