GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hyperf/validation: Validation component for Hyperf

BranchesTags
Open more actions menu

Latest commit

 

History

237 Commits
237 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
publish
publish
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 

Repository files navigation

Hyperf Validation

About

hyperf/validation 组件衍生于 Laravel Validation 组件的,我们对它进行了一些改造,大部分功能保持了相同。在这里感谢一下 Laravel 开发组,实现了如此强大好用的 Validation 组件。

Installation

composer require hyperf/validation

Config

Publish config file

# 发布国际化配置,已经发布过国际化配置可以省略
php bin/hyperf.php vendor:publish hyperf/translation

php bin/hyperf.php vendor:publish hyperf/validation

Configuration path

your/config/path/autoload/translation.php

Configuration

<?php
return [
    'locale' => 'zh_CN',
    'fallback_locale' => 'en',
    'path' => BASE_PATH . '/storage/languages',
];

Exception handler

<?php
return [
    'handler' => [
        'http' => [
            \Hyperf\Validation\ValidationExceptionHandler::class,
        ],
    ],
];

Validation middleware

<?php
return [
    'http' => [
        \Hyperf\Validation\Middleware\ValidationMiddleware::class,
    ],
];

Usage

Generate form request

Command:

php bin/hyperf.php gen:request FooRequest

Usage:

class IndexController
{
    public function foo(FooRequest $request)
    {
        $request->input('foo');
    }
    
    public function bar(RequestInterface $request)
    {
        $factory = $this->container->get(\Hyperf\Validation\Contract\ValidatorFactoryInterface::class);

        $factory->extend('foo', function ($attribute, $value, $parameters, $validator) {
            return $value == 'foo';
        });

        $factory->replacer('foo', function ($message, $attribute, $rule, $parameters) {
            return str_replace(':foo', $attribute, $message);
        });

        $validator = $factory->make(
            $request->all(),
            [
                'name' => 'required|foo',
            ],
            [
                'name.foo' => ':foo is not foo',
            ]
        );

        if (!$validator->passes()) {
             $validator->errors();
        }
    }
}

About

Validation component for Hyperf

hyperf.io

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

12 stars

Watchers

3 watching

Forks

10 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.