juststeveking / fluent-validation
Fluent Validation is a helper package, that allows you to use sensible defaults for your Laravel validation rules.`
                                    Fund package maintenance!
                                                                            
                                                                                                                                        JustSteveKing
                                                                                    
                                                                
Installs: 568
Dependents: 0
Suggesters: 0
Security: 0
Stars: 25
Watchers: 1
Forks: 2
Open Issues: 0
Type:package
pkg:composer/juststeveking/fluent-validation
Requires
- php: ^8.1
Requires (Dev)
- laravel/pint: ^1.2
- orchestra/testbench: ^7.11
- pestphp/pest: ^1.22
- phpstan/phpstan: ^1.9
README
Fluent Validation is a helper package, that allows you to use sensible defaults for your Laravel validation rules.
Installation
composer require juststeveking/fluent-validation
Why??
Why did I create this package? Well to be honest, I was feeling lazy - but a productive kind of lazy. I was writing some validation for quite a large API request and looked at all the string input I was about to have to validate, and thought there must be an easier way. So I created this to save me time by taking time building a package. I got the last laugh though, as now I never have to write the same string validation again!
Usage
To use this package all you need to do is include the rules you may wish to use:
Validating emails
return [ 'email' => \JustSteveKing\FluentValidation\Fluency\EmailRule::rules() ];
Or to build them up yourself and/or override them:
return [ 'email' => [ \JustSteveKing\FluentValidation\Rules\Required::rule(), \JustSteveKing\FluentValidation\Rules\Email::rule('rfc,dns'), ] ];
Validating Passwords
return [ 'password' => \JustSteveKing\FluentValidation\Fluency\PasswordRule::rules() ];
Or to build them up yourself and/or override them:
return [ 'password' => [ \JustSteveKing\FluentValidation\Rules\Required::rule(), \Illuminate\Validation\Rules\Password::default(), ] ];
Validating Strings
return [ 'title' => \JustSteveKing\FluentValidation\Fluency\StringRule::rules() ];
Or to build them up yourself and/or override them:
return [ 'title' => [ \JustSteveKing\FluentValidation\Rules\Required::rule(), \JustSteveKing\FluentValidation\Rules\Text::rule(), \JustSteveKing\FluentValidation\Rules\Min::rule(2), \JustSteveKing\FluentValidation\Rules\Max::rule(255), ] ];
Available Fluency Rules
This is a list of the currently available Fluency Rules:
- EmailRule- Will return- requiredand- emailrules.
- PasswordRule- Will return- requiredand- Password::default()rules from Laravel.
- StringRule- Will return- required,- min:2, and- max:255rules.
Available Rules
This is a list of the currently available Rules:
- Accepted- Will return- acceptedor whatever override input you pass.
- After- Will return- after:and whatever override input you pass.
- AfterOrEqual- Will return- after_or_equal:and whatever override input you pass.
- Alpha- Will return- alphaor whatever override input you pass.
- Boolean- Will return- booleanor whatever override input you pass.
- Date- Will return- dateor whatever override input you pass.
- Email- Will return- email:and whatever override input you pass.
- Enum- Will return a new Laravel Enum validation rule, you must pass a backed Enum to this instance using- YourEnum::class.
- Exists- Will return- exists:with whatever table and an optional column you pass to it.
- Integer- Will return- integeror whatever override input you pass.
- Max- Will return- max:and whatever override input you pass.
- Min- Will return- min:and whatever override input you pass.
- Required- Will return- requiredor whatever override input you pass.
- Text- Will return- stringor whatever override input you pass.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.