'required|integer:strict', 'list_rows' => 'required|integer:strict', ]; } /** * 获取已定义验证规则的错误消息 */ public function messages(): array { return [ 'page.required' => '页码不能为空', ]; } /** * 验证的各字段的含义 * @return array|string[] */ public function attributes(): array { return [ 'page' => '页码', ]; } /** * 表单请求后钩子 * @param $validator */ public function withValidator($validator) { $validator->after(function ($validator) { //获取参数 $params = $this->validationData(); if (isset($params['page']) && $params['page'] <= 0) { return $validator->errors()->add('page', 'page 数据有误'); } if (isset($params['list_rows']) && $params['page'] <= 0) { return $validator->errors()->add('list_rows', 'list_rows 数据有误'); } }); } }