BaseRequest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * 描述
  4. * @auth nj911<nj-x@gmail.com>
  5. * @date: 2021-04-18 12:25
  6. */
  7. namespace Modules\AgentApi\Requests;
  8. use App\Exceptions\ApiException;
  9. use Illuminate\Foundation\Http\FormRequest;
  10. use \Illuminate\Contracts\Validation\Validator;
  11. class BaseRequest extends FormRequest
  12. {
  13. /**
  14. * Determine if the user is authorized to make this request.
  15. *
  16. * @return bool
  17. */
  18. public function authorize()
  19. {
  20. //默认放行auth校验
  21. return true;
  22. }
  23. /**
  24. * Get the validation rules that apply to the request.
  25. *
  26. * @return array
  27. */
  28. public function rules()
  29. {
  30. return [
  31. //
  32. ];
  33. }
  34. /**
  35. * 重定义校验失败
  36. * @param Validator $validator
  37. * @throws ApiException
  38. */
  39. protected function failedValidation(Validator $validator)
  40. {
  41. throw new ApiException($validator->messages()->first(), 500);
  42. }
  43. /**
  44. * 重定义认证失败
  45. * @throws ApiException
  46. */
  47. protected function failedAuthorization()
  48. {
  49. throw new ApiException('认证错误', 403);
  50. }
  51. }