1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * @Name
- * @Description
- * @Author 刘学玺
- * @Date 2024/3/20 14:54
- */
- namespace App\Http\Requests\Frontend\Client\Coach;
- use App\Http\Requests\Request;
- use Illuminate\Support\Facades\Route;
- use Illuminate\Validation\Rule;
- class UserRequest extends Request
- {
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array<string, array|string>
- */
- public function rules(): array
- {
- $rules = [
- 'categoryId' => ['bail', 'integer'],
- 'sort' => ['bail', 'string', Rule::in(['order', 'distance'])]
- ];
- $actionName = last(explode('@', Route::current()->getActionName()));
- if ($actionName === 'index') {
- $rules = [
- 'cityCode' => ['bail', 'required', 'string'],
- 'distance' => ['bail', 'integer', 'between:1,10'],
- 'lat' => ['bail', 'required', 'string'],
- 'lng' => ['bail', 'required', 'string'],
- ];
- }
- if($actionName === 'show'){
- $rules = [
- 'categoryId' => ['bail', 'integer'],
- 'lat' => ['bail', 'required', 'string'],
- 'lng' => ['bail', 'required', 'string'],
- ];
- }
- if ($actionName === 'apply') {
- $rules = [
- 'name' => ['bail', 'required', 'string', 'max:50'],
- 'sex' => ['bail', 'required', 'integer', Rule::in([0, 1])],
- 'birthday' => ['bail', 'nullable', 'string'],
- 'mobile' => ['bail', 'nullable', 'string'],
- 'city' => ['bail', 'nullable', 'string'],
- 'workImg' => ['bail', 'required', 'nullable', 'string'],
- ];
- }
- return $rules;
- }
- public function messages(): array
- {
- return [
- 'name.required' => '姓名不能为空!',
- 'workImg.bail' => '工作照不能为空!',
- 'workImg.required' => '工作照不能为空!',
- 'workImg.nullable' => '工作照不能为空!1',
- 'sex.required' => '性别不能为空!',
- 'sex.in' => '性别取值范围错误!',
- '*' => '参数或类型错误!'
- ];
- }
- }
|