ForeignHaiRobotic_taskUpdateRequest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Services\LogService;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Validator;
  6. class ForeignHaiRobotic_taskUpdateRequest 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. 'groupCode'=>'required',
  26. 'taskCode'=>'required',
  27. 'updateEventType'=>'required|in:0,1',
  28. 'status'=>'required|in:0,1',
  29. 'binCode'=>'required',
  30. 'kubotId'=>'required',
  31. 'description'=>'nullable',
  32. ];
  33. }
  34. public function withValidator(Validator $validator)
  35. {
  36. $validator->after(function (Validator $validator) {
  37. if($validator->errors()->isNotEmpty()){
  38. $validator->errors()->add('code','422');
  39. $validator->errors()->add('errMsg', json_encode($validator->errors()->messages(),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
  40. $validator->errors()->add('data',$validator->errors()->toJson(JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
  41. }
  42. });
  43. }
  44. }