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']
// ...
]));
You can install the package via composer:
composer require soyhuce/laravel-validation-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)
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'
),
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.