Package Data | |
---|---|
Maintainer Username: | trueifnotfalse |
Maintainer Contact: | nick@epautomotive.org (Nick Wilging) |
Package Create Date: | 2023-08-24 |
Package Last Update: | 2023-08-24 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-09 15:10:06 |
Package Statistics | |
---|---|
Total Downloads: | 3,123 |
Monthly Downloads: | 319 |
Daily Downloads: | 7 |
Total Stars: | 0 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Ensures incoming form request data is of a certain datatype.
While Lumen includes many useful validation rules out of the box, it lacks the ability to validate data type as well
as content type. There have been a couple
complaints about this over the years, but due to the versatile nature of
Laravel, it doesn't seem likely that validation rules such as integer
or boolean
will begin validating that the data
is actually of the desired type.
This package provides a way for you to require the incoming data to be of a given type, such as int
, bool
, float
, etc.
composer require trueifnotfalse/lumen-strict-types-validation
Add to bootstrap/app.php
and register the Service Provider.
$app->register(TrueIfNotFalse\LumenStrictValidation\Providers\StrictValidationProvider::class);
When constructing validation rules, simply add type-<desired type>
to the validation rules string/array.
$rules = [
'id' => 'required|type-int', # This will require the incoming `id` to be an integer.
];
The failure message format is:
The :attribute must be of type :type
Where attribute
is the attribute being validated (id
from the above example) and type
is the desired type to validate
against (int
in the above example).
If the above example failed, we would receive this message:
The id must be of type int