<?php
namespace App\Controller;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
class TestController
{
/**
* @Inject()
* @var ValidatorFactoryInterface
*/
protected $validationFactory;
public function test(RequestInterface $request)
{
$validator = $this->validationFactory->make(
$request->all(),
// hello限制值必须存在于[1, 2]
// 错误写法:['hello' => ['required', 'integer', [1, 2]]]
// 正确写法:使用Rule::in
['hello' => ['required', 'integer', Rule::in([1, 2])]]
);
}
}
[Hyperf]Method Hyperf\Validation\Validator::validate1 does not exist
于 2021-10-10 11:45:48 首次发布