validate-laravel maintained by hampel
Additional Laravel Validation Rules
This package is abandoned
It is no longer maintained and will receive no further releases.
There is no replacement package. What these rules add over Laravel's own
ip,ipv4andipv6is twofilter_varconstants, so the shortest migration is to keep the rule in your own application:use Closure; use Illuminate\Contracts\Validation\ValidationRule; class PublicIp implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { $valid = filter_var( $value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ); if ($valid === false) { $fail('The :attribute must be a valid public IP address.'); } } }Add
FILTER_FLAG_IPV4orFILTER_FLAG_IPV6to restrict it to one family. If you want the same checks outside Laravel, hampel/validate has them asisPublicIp(),isPublicIpv4()andisPublicIpv6(), with no framework attached.The last release here is 2.13.0, which works with Laravel 9. Everything below documents that release.
mastercarries later work that was never tagged and is not on Packagist: the rules were rewritten as rule objects, andbool_equivanduploaded_filewere dropped rather than ported.
Custom Validators for Laravel
By Simon Hampel
Installation
The recommended way of installing this validation library is through Composer:
Require the package via Composer in your composer.json
{
"require": {
"hampel/validate-laravel": "^2.8"
}
}
Run Composer to update the new requirement.
$ composer update
The package is built to work with the Laravel Framework.
Notes
Version 2.8 of this library renames the bool rule to bool_equiv to avoid conflicts with the core bool rule.
Version 2.0 of this library removes several rules previously available:
unique_or_zero and exists_or_zero have been removed as they were deemed to be of little value
domain, domain_in, tld and tld_in have been moved to a new package hampel/tlds.
The getTlds helper function has also been removed and you should install the hampel/tlds package to gain access to all new functions for retrieving an up-to-date list of all valid TLDs directly from IANA or other sources.
Usage
This package adds additional validators for Laravel - refer to Laravel Documentation - Validation for general usage instructions.
bool_equiv
The field under validation must be the equivalent of a "boolean" (either true or false) in a variety of forms.
Acceptable values include: "1", "true", "on" and "yes", "0", "false", "off", "no", "", and NULL
ipv4_public
The field under validation must be a public IPv4 address - ie. not in the "private" or "reserved" ranges.
ipv6_public
The field under validation must be a public IPv6 address - ie. not in the "private" or "reserved" ranges.
ip_public
The field under validation must be a public IPv4 or IPv6 address - ie. not in the "private" or "reserved" ranges.
uploaded_file
The field under validation must be an uploaded file of type Symfony\Component\HttpFoundation\File\UploadedFile, as
returned from Input::file(). The file upload must also be valid, that is, the upload must have succeeded with an error
return of UPLOAD_ERR_OK
(see File Upload Error Messages Explained for more details
on file upload errors)