<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use App\Request\FooRequest;
use App\Request\SceneRequest;


class IndexController extends AbstractController
{
    #[Inject]
    protected ValidatorFactoryInterface $validationFactory;

    public function index(RequestInterface $request){
        $validator = $this->validationFactory->make(
            $request->all(),
            [
                'foo' => 'required',
                'bar' => 'required',
            ],
            [
                'foo.required' => 'foo必填',
                'bar.required' => 'bar必填',
            ]
        );

        if ($validator->fails()){
            // Handle exception
            $errorMessage = $validator->errors()->first();
            var_dump($errorMessage);
        }
    }
}
