ForeignHaiRobotic_taskUpdateRequest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 false;
  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',
  28. 'status'=>'required',
  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()));
  40. $validator->errors()->add('data',$validator->errors()->toJson());
  41. }
  42. $errMsg=(function()use($validator){
  43. if($validator->errors()->isEmpty())return '';
  44. return $errMsg = '错误: '.$validator->errors()->toJson();
  45. })();
  46. LogService::log(__METHOD__,__FUNCTION__,
  47. $errMsg??''
  48. .'请求:'.json_encode($this->all())
  49. .'调用堆栈:'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3))
  50. );
  51. });
  52. }
  53. }