|
11 | 11 |
|
12 | 12 | namespace LaravelJsonApi\Eloquent\Filters; |
13 | 13 |
|
| 14 | +use Illuminate\Http\Request; |
| 15 | +use LaravelJsonApi\Core\Query\Input\Query; |
14 | 16 | use LaravelJsonApi\Eloquent\Contracts\Filter; |
15 | 17 | use LaravelJsonApi\Eloquent\Filters\Concerns\HasRelation; |
16 | 18 | use LaravelJsonApi\Eloquent\Filters\Concerns\IsSingular; |
17 | 19 | use LaravelJsonApi\Eloquent\Schema; |
| 20 | +use LaravelJsonApi\Validation\Filters\Validated; |
| 21 | +use LaravelJsonApi\Validation\Rules\JsonBoolean; |
18 | 22 | use function filter_var; |
19 | 23 |
|
20 | 24 | class Has implements Filter |
21 | 25 | { |
22 | 26 | use HasRelation; |
23 | 27 | use IsSingular; |
| 28 | + use Validated; |
24 | 29 |
|
25 | 30 | /** |
26 | 31 | * Create a new filter. |
27 | 32 | * |
28 | 33 | * @param Schema $schema |
29 | 34 | * @param string $fieldName |
30 | 35 | * @param string|null $key |
31 | | - * @return static |
| 36 | + * @return self |
32 | 37 | */ |
33 | | - public static function make(Schema $schema, string $fieldName, string $key = null) |
| 38 | + public static function make(Schema $schema, string $fieldName, string $key = null): self |
34 | 39 | { |
35 | 40 | return new static($schema, $fieldName, $key); |
36 | 41 | } |
@@ -64,13 +69,21 @@ public function apply($query, $value) |
64 | 69 | return $query->doesntHave($relationName); |
65 | 70 | } |
66 | 71 |
|
| 72 | + /** |
| 73 | + * @inheritDoc |
| 74 | + */ |
| 75 | + public function validationRules(?Request $request, Query $query): array |
| 76 | + { |
| 77 | + return [(new JsonBoolean())->asString()]; |
| 78 | + } |
| 79 | + |
67 | 80 | /** |
68 | 81 | * Deserialize the value. |
69 | 82 | * |
70 | 83 | * @param mixed $value |
71 | 84 | * @return bool |
72 | 85 | */ |
73 | | - protected function deserialize($value): bool |
| 86 | + protected function deserialize(mixed $value): bool |
74 | 87 | { |
75 | 88 | return filter_var($value, FILTER_VALIDATE_BOOL); |
76 | 89 | } |
|
0 commit comments