| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- /**
- * 描述
- * @auth nj911<nj-x@gmail.com>
- * @date: 2021-04-18 12:25
- */
- namespace Modules\Api\Requests;
- use App\Exceptions\ApiException;
- use Illuminate\Foundation\Http\FormRequest;
- use \Illuminate\Contracts\Validation\Validator;
- 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 Validator $validator
- * @throws ApiException
- */
- protected function failedValidation(Validator $validator)
- {
- throw new ApiException($validator->messages()->first(), 500);
- }
- /**
- * 重定义认证失败
- * @throws ApiException
- */
- protected function failedAuthorization()
- {
- throw new ApiException('认证错误', 403);
- }
- }
|