ParkingRequest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Arr;
  5. class ParkingRequest 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('parking'))->id;
  24. $rules = [
  25. 'name' => 'required|max:255|unique:parkings,name,'.$id,
  26. 'parking_fence' => 'required',
  27. 'area_id' => 'required',
  28. 'status' => 'required|boolean',
  29. 'max_number' => 'max:5',
  30. 'type' => '',
  31. //
  32. ];
  33. if ($this->isMethod('put')) {
  34. $rules = Arr::only($rules, $this->keys());
  35. }
  36. return $rules;
  37. }
  38. public function attributes()
  39. {
  40. return [
  41. 'name' => '区域名称',
  42. 'parking_fence' => '停车区域',
  43. 'area_id' => '所属大区',
  44. 'type' => '区域类型',
  45. 'max_number' => '最大停车数',
  46. 'status' => '区域状态'
  47. ];
  48. }
  49. }