lexal/laravel-step-validator

Laravel & Lumen Step validator.

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

This package is auto-updated.

Last update: 2024-10-28 23:36:21 UTC


README

PHPUnit, PHPCS, PHPStan Tests

The package is built for validating step data on the BeforeHandleStep event of Stepped Form.

Requirements

PHP: >=8.1

Laravel: ^9.0 || ^10.0

Installation

Via Composer

composer require lexal/laravel-step-validator

Additional changes for Lumen framework

Add the following snippet to the bootstrap/app.php file under the providers section as follows:

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

Usage

Implement ValidatableStepInterface for the step and the listener will validate step data before handling the step. The validator will pass RulesDefinition data directly to the Laravel validator factory method.

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) */,
        );
    }
}

License

Laravel & Lumen Step Validator is licensed under the MIT License. See LICENSE for the full license text.