123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- declare(strict_types=1);
- namespace App\Request\Api\v1;
- use Hyperf\Validation\Request\FormRequest;
- class DemoIndexRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- */
- public function rules(): array
- {
- return [
- 'page' => 'nullable|integer',
- 'size' => 'nullable|integer',
- 'push_cid' => 'nullable|string',
- 'platform' => 'nullable|string',
- 'ring_name' => 'nullable|string',
- 'order_no' => 'nullable|string',
- ];
- }
- /**
- * 获取已定义验证规则的错误消息
- */
- 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['size']) && $params['page'] <= 0) {
- return $validator->errors()->add('size', 'size 数据有误');
- }
- });
- }
- }
|