| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * 描述.
- *
- * @author nj <nj@gmail.com>
- * @date 2019-11-03 17:44:30
- */
- declare(strict_types=1);
- namespace Modules\Api\Requests;
- use Hyperf\Contract\ValidatorInterface;
- use App\Exception\ApiException;
- use Hyperf\Validation\Request\FormRequest;
- class BaseRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize()
- {
- // 默认放行auth校验,不通过其他方式鉴权.
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- return [
- ];
- }
- /**
- * 重定义校验失败
- * @param ValidatorInterface $validator
- * @throws ApiException
- */
- protected function failedValidation(ValidatorInterface $validator)
- {
- throw new ApiException($validator->messages()->first(), 500);
- }
- /**
- * 重定义认证失败
- * @throws ApiException
- */
- protected function failedAuthorization()
- {
- throw new ApiException(trans('common.err_failed_authorization'), 403);
- }
- }
|