UserRequest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @Name
  4. * @Description
  5. * @Author 刘学玺
  6. * @Date 2024/3/20 14:54
  7. */
  8. namespace App\Http\Requests\Frontend\Client\Coach;
  9. use App\Http\Requests\Request;
  10. use Illuminate\Support\Facades\Route;
  11. use Illuminate\Validation\Rule;
  12. class UserRequest extends Request
  13. {
  14. /**
  15. * Get the validation rules that apply to the request.
  16. *
  17. * @return array<string, array|string>
  18. */
  19. public function rules(): array
  20. {
  21. $rules = [
  22. 'categoryId' => ['bail', 'integer'],
  23. 'sort' => ['bail', 'string', Rule::in(['order', 'distance'])]
  24. ];
  25. $actionName = last(explode('@', Route::current()->getActionName()));
  26. if ($actionName === 'index') {
  27. $rules = [
  28. 'cityCode' => ['bail', 'required', 'string'],
  29. 'distance' => ['bail', 'integer', 'between:1,10'],
  30. 'lat' => ['bail', 'required', 'string'],
  31. 'lng' => ['bail', 'required', 'string'],
  32. ];
  33. }
  34. if($actionName === 'show'){
  35. $rules = [
  36. 'categoryId' => ['bail', 'integer'],
  37. 'lat' => ['bail', 'required', 'string'],
  38. 'lng' => ['bail', 'required', 'string'],
  39. ];
  40. }
  41. if ($actionName === 'apply') {
  42. $rules = [
  43. 'name' => ['bail', 'required', 'string', 'max:50'],
  44. 'sex' => ['bail', 'required', 'integer', Rule::in([0, 1])],
  45. 'birthday' => ['bail', 'nullable', 'string'],
  46. 'mobile' => ['bail', 'nullable', 'string'],
  47. 'city' => ['bail', 'nullable', 'string'],
  48. 'workImg' => ['bail', 'required', 'nullable', 'string'],
  49. ];
  50. }
  51. return $rules;
  52. }
  53. public function messages(): array
  54. {
  55. return [
  56. 'name.required' => '姓名不能为空!',
  57. 'workImg.bail' => '工作照不能为空!',
  58. 'workImg.required' => '工作照不能为空!',
  59. 'workImg.nullable' => '工作照不能为空!1',
  60. 'sex.required' => '性别不能为空!',
  61. 'sex.in' => '性别取值范围错误!',
  62. '*' => '参数或类型错误!'
  63. ];
  64. }
  65. }