Skip to content

microdel/php-laravel-fluent-validation

 
 

Repository files navigation

Fluent Validation Rules builders for Laravel

Build Status Latest Stable Version License

Use fluent-style syntax to build Laravel validation rules

Example:

$rules = [
    'id' => Rule::int()->required(),
    'name' => Rule::string()->required()->minLength(3)->toString(),
    'email' => Rule::string()->required()->email()->toArray()
]

Advantages

  • Strong typing
  • Intellisence for available rules and parameters (if you use smart IDE, like PHPStorm)
  • Hints about mistypings (if you use smart IDE, like PHPStorm)

Examples

Inline documentation:

Inline documentation

Inellisence:

Intelisence

Custom validation rules

You can also use custom declared validations:

$rules = [
    ... => Rule::custom('foo')
]

Installation

Install the saritasa/laravel-fluent-validation package:

$ composer require saritasa/laravel-fluent-validation

Add the FluentValidationServiceProvider in config/app.php:

'providers' => array(
    // ...
    Saritasa\Laravel\Validation\FluentValidationServiceProvider::class,
)

Note: You can omit service provider registration, but then you must call ->toString() or ->toArray() on each builder. If service provider is registered, manual casting of rule to string or array is not necessary and default Laravel's Illuminate\Validation\ValidationServiceProvider::class can be removed from 'providers' array.

Available classes

\Saritasa\Laravel\Validation\Rule

Root of your rule builder.

Contributing

  1. Create fork
  2. Checkout fork
  3. Develop locally as usual. Code must follow PSR-1, PSR-2
  4. Update README.md to describe new or changed functionality. Add changes description to CHANGES.md file.
  5. When ready, create pull request

Resources

About

Fluid-style validation rules builder for Laravel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%