lexal/laravel-step-validator

Laravel & Lumen 步骤验证器。

v2.0.0 2023-12-28 21:38 UTC

This package is auto-updated.

Last update: 2024-09-28 23:16:44 UTC


README

PHPUnit, PHPCS, PHPStan Tests

该包用于在Stepped FormBeforeHandleStep事件上验证步骤数据。

要求

PHP >=8.1

Laravel ^9.0 || ^10.0

安装

通过Composer

composer require lexal/laravel-step-validator

Lumen框架的附加更改

将以下片段添加到bootstrap/app.php文件中的 providers 部分,如下所示

$app->register(Lexal\LaravelStepValidator\ServiceProvider\ServiceProvider::class);

用法

为步骤实现ValidatableStepInterface,监听器将在处理步骤之前验证步骤数据。验证器将直接将RulesDefinition数据传递给Laravel验证器工厂方法。

use Lexal\LaravelStepValidator\RulesDefinition;
use Lexal\LaravelStepValidator\Steps\ValidatableStepInterface;
use Lexal\SteppedForm\Steps\RenderStepInterface;

final class CustomerStep implements RenderStepInterface, ValidatableStepInterface
{
    public function getRulesDefinition(mixed $entity): RulesDefinition
    {
        return new RulesDefinition(
            /* rules */,
            /* messages (default - empty array) */,
            /* custom attributes (default - empty array) */,
        );
    }
}

许可

Laravel & Lumen Step Validator遵循MIT许可证。有关完整的许可文本,请参阅LICENSE