BikeRequest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Arr;
  5. class BikeRequest extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. $id = (int)optional($this->route('bike'))->id;
  24. $rules = [
  25. 'bike_no' => 'required|unique:bikes,bike_no,' . $id,
  26. 'box_no' => 'sometimes|unique:bikes,box_no,' . $id,
  27. 'battery_power' => '',
  28. 'is_link' => '',
  29. 'is_lock' => '',
  30. 'is_low_battery_power' => '',
  31. 'is_riding' => '',
  32. 'is_trouble' => '',
  33. 'last_use_bike_end_time' => '',
  34. 'last_location' => '',
  35. 'last_location_time' => '',
  36. 'put_area_id' => '',
  37. 'put_status' => 'required',
  38. 'put_time' => '',
  39. ];
  40. if ($this->isMethod('put')) {
  41. $rules = Arr::only($rules, $this->keys());
  42. }
  43. return $rules;
  44. }
  45. public function attributes()
  46. {
  47. return [
  48. 'bike_no' => '车辆编号',
  49. 'box_no' => '控制设备编号',
  50. 'battery_power' => '电量',
  51. 'is_link' => '是否在线',
  52. 'is_lock' => '是否锁车',
  53. 'is_low_battery_power' => '是否电量低',
  54. 'is_riding' => '是否骑行',
  55. 'is_trouble' => '是否故障',
  56. 'last_use_bike_end_time' => '最后骑行时间',
  57. 'last_location' => '最后位置信息',
  58. 'last_location_time' => '最后定位时间',
  59. 'put_area_id' => '投放区域id',
  60. 'put_status' => '投放状态',
  61. 'put_time' => '投放时间',
  62. ];
  63. }
  64. }