1. Go to this page and download the library: Download hyperf-plus/validate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hyperf-plus / validate example snippets
use HPlus\Route\Annotation\PostApi;
use HPlus\Route\Annotation\ApiController;
use HPlus\Validate\Annotations\RequestValidation;
#[ApiController(prefix: '/api/users')]
class UserController
{
#[PostApi]
#[RequestValidation(
rules: [
'name' => 'c function create()
{
return ['message' => 'success'];
}
}
// 定义验证器
use Hyperf\Validation\Request\FormRequest;
class CreateUserRequest extends FormRequest
{
protected array $scenes = [
'create' => ['name', 'email', 'password'],
'update' => ['name', 'email'],
];
public function rules(): array
{
return [
'name' => 'rRequest::class, scene: 'create')]
public function create() {}