Skip to content

Commit 5dec36b

Browse files
committed
Optimized
1 parent 49980f0 commit 5dec36b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Request/FormRequest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Hyperf\Utils\Context;
1818
use Hyperf\Validation\Contracts\Validation\Factory as ValidationFactory;
1919
use Hyperf\Validation\Contracts\Validation\ValidatesWhenResolved;
20+
use Hyperf\Validation\UnauthorizedException;
2021
use Hyperf\Validation\ValidatesWhenResolvedTrait;
2122
use Hyperf\Validation\ValidationException;
2223
use Psr\Container\ContainerInterface;
@@ -63,6 +64,14 @@ public function response(): ResponseInterface
6364
return $response->withStatus(422);
6465
}
6566

67+
/**
68+
* Get the validated data from the request.
69+
*/
70+
public function validated(): array
71+
{
72+
return $this->getValidatorInstance()->validated();
73+
}
74+
6675
/**
6776
* Get custom messages for validator errors.
6877
*/
@@ -167,6 +176,6 @@ protected function passesAuthorization(): bool
167176
*/
168177
protected function failedAuthorization()
169178
{
170-
// throw new AuthorizationException('This action is unauthorized.');
179+
throw new UnauthorizedException('This action is unauthorized.');
171180
}
172181
}

src/ValidatesWhenResolvedTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ protected function prepareForValidation()
4747

4848
/**
4949
* Get the validator instance for the request.
50-
*
51-
* @return ValidatorInterface
5250
*/
53-
protected function getValidatorInstance()
51+
protected function getValidatorInstance(): ValidatorInterface
5452
{
5553
return $this->validator();
5654
}

0 commit comments

Comments
 (0)