soyhuce / laravel-validation-rules
A set of useful validation rules for Laravel
Fund package maintenance!
soyhuce
Installs: 8 984
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/support: ^10.0 || ^11.0
- illuminate/translation: ^10.0 || ^11.0
- illuminate/validation: ^10.0 || ^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.7
- larastan/larastan: ^2.0.1
- nunomaduro/collision: ^7.10 || ^8.1
- orchestra/testbench: ^8.0 || ^9.0
- pestphp/pest: ^2.24
- pestphp/pest-plugin-laravel: ^2.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.4
README
Main objective of this package is to provide a set of validation rules for Laravel in order to make it easier to write validation.
Validator::make($data, rules([ 'email' => ['required', DbRules::string()], // ['required', 'string', 'max:255'] 'smaller' => ['nullable', DbRules::string(20)], // ['nullable', 'string', 'max:20'] 'birthday' => [DbRules::date()], // ['date_format:Y-m-d'] 'tiny' => [DbRules::tinyInteger()], // ['integer', 'min:-128', 'max:127'] // ... ]));
Installation
You can install the package via composer:
composer require soyhuce/laravel-validation-rules
Usage
Available Rules
Database related rules :
DbRules::string
DbRules::boolean
DbRules::enum
DbRules::date
DbRules::dateTime
DbRules::tinyInteger
DbRules::unsignedTinyInteger
DbRules::smallInteger
DbRules::unsignedSmallInteger
DbRules::mediumInteger
DbRules::unsignedMediumInteger
DbRules::integer
DbRules::unsignedInteger
DbRules::bigInteger
DbRules::unsignedBigInteger
DbRules::smallIncrements
DbRules::mediumIncrements
DbRules::increments
DbRules::bigIncrements
DbRules::float
DbRules::double
Miscellaneous rules :
MisRules::safePassword
: GDPR/CNIL compatible password (at least 12 characters)MisRules::mediumPassword
: GDPR/CNIL compatible password (at least 8 characters)
Using in conditional Rule::when
Rules extending CompoundRule
cannot be used directly in Rule::when
.
You will need to use ...
in this case :
'commission_account' => Rule::when( fn(Fluent $data) => $data->get('commission') !== null, - ['required', DbRules::string()], + ['required', ...DbRules::string()], 'exclude' ),
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
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.