nwilging / laravel-strict-types-validation
A validator for laravel to require strict types in form request data
Installs: 1 570
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
- laravel/framework: >=8
Requires (Dev)
- dealerinspire/laravel-coding-standard: ^2.0
- mockery/mockery: ^1.5
- orchestra/testbench: >=5
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-11-25 03:31:47 UTC
README
Ensures incoming form request data is of a certain datatype.
About
While Laravel 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.
Installation
Pre Requisites
- Laravel v8+
- PHP 7.4+
Install with Composer
composer require nwilging/laravel-strict-types-validation
Usage
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.
];
Failure Messages
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