ApiRequest.php 719 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Exceptions\ApiException;
  4. use Illuminate\Contracts\Validation\Validator;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. class ApiRequest extends FormRequest
  7. {
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. *
  11. * @return bool
  12. */
  13. public function authorize()
  14. {
  15. return true;
  16. }
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array
  21. */
  22. public function rules()
  23. {
  24. return [
  25. //
  26. ];
  27. }
  28. protected function failedValidation(Validator $validator)
  29. {
  30. throw new ApiException(422, "Validation error", $validator->errors());
  31. }
  32. }