OpenProjectRequest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Requests\Coach;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * 技师开通项目请求验证
  6. */
  7. class OpenProjectRequest 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. 'action' => 'required|string|in:open,close',
  26. ];
  27. }
  28. /**
  29. * 获取验证错误消息
  30. *
  31. * @return array<string, string> 错误消息数组
  32. */
  33. public function messages(): array
  34. {
  35. return [
  36. 'project_id.required' => '项目ID不能为空',
  37. 'project_id.integer' => '项目ID必须是整数',
  38. 'project_id.exists' => '项目不存在',
  39. 'action.required' => '操作类型不能为空',
  40. 'action.string' => '操作类型必须是字符串',
  41. 'action.in' => '操作类型只能是开通或关闭',
  42. ];
  43. }
  44. }