SetProjectRequest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Http\Requests\Coach;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * 技师项目设置请求验证
  6. */
  7. class SetProjectRequest extends FormRequest
  8. {
  9. /**
  10. * 判断用户是否有权限进行此请求
  11. */
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * 获取验证规则
  18. *
  19. * @return array<string, mixed> 验证规则数组
  20. */
  21. public function rules(): array
  22. {
  23. return [
  24. 'project_id' => 'required|integer|exists:project,id',
  25. 'voucher' => 'nullable|numeric|min:0|max:10',
  26. 'gender' => 'nullable|integer|in:0,1,2',
  27. 'traffic_fee_type' => 'nullable|integer|in:0,1,2',
  28. ];
  29. }
  30. /**
  31. * 获取验证错误消息
  32. *
  33. * @return array<string, string> 错误消息数组
  34. */
  35. public function messages(): array
  36. {
  37. return [
  38. 'project_id.required' => '项目ID不能为空',
  39. 'project_id.integer' => '项目ID必须是整数',
  40. 'project_id.exists' => '项目不存在',
  41. 'voucher.numeric' => '代金券金额必须是数字',
  42. 'voucher.min' => '代金券金额不能小于0元',
  43. 'voucher.max' => '代金券金额不能超过10元',
  44. 'gender.integer' => '顾客性别设置必须是整数',
  45. 'gender.in' => '顾客性别设置值无效',
  46. 'traffic_fee_type.integer' => '交通费类型必须是整数',
  47. 'traffic_fee_type.in' => '交通费类型值无效',
  48. ];
  49. }
  50. }