Download the PHP package spatie/laravel-validation-rules without Composer

On this page you can find all versions of the php package spatie/laravel-validation-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-validation-rules

A set of useful Laravel validation rules

Latest Version on Packagist Tests Total Downloads

This repository contains some useful Laravel validation rules.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

The package will automatically register itself.

Translations

If you wish to edit the package translations, you can run the following command to publish them into your resources/lang folder

Available rules

Authorized

Determine if the user is authorized to perform an ability on an instance of the given model. The id of the model is the field under validation

Consider the following policy:

This validation rule will pass if the id of the logged in user matches the user_id on TestModel who's it is in the model_id key of the request.

Optionally, you can provide an authentication guard as the third parameter.

Model resolution

If you have implemented the getRouteKeyName method in your model, it will be used to resolve the model instance. For further information see Customizing The Default Key Name

CountryCode

Determine if the field under validation is a valid 2 letter ISO3166 country code (example of valid country codes: GB, DK, NL).

Note that this rule requires the package league/iso3166 to be installed: composer require league/iso3166

If you want to validate a nullable country code field, you can call the nullable() method on the CountryCode rule. This way null and 0 are also passing values:

Currency

Determine if the field under validation is a valid 3 letter ISO4217 currency code (example of valid currencies: EUR, USD, CAD).

Note that this rule require the package league/iso3166 to be installed: composer require league/iso3166

If you want to validate a nullable currency field, simple do not let it be required as described in the Laravel Docs for implicit validation rules:

... when an attribute being validated is not present or contains an empty string, normal validation rules, including custom rules, are not run

Enum

This rule will validate if the value under validation is part of the given enum class. We assume that the enum class has a static toArray method that returns all valid values. If you're looking for a good enum class, take a look at spatie/enum or myclabs/php-enum.

Consider the following enum class:

The Enum rule can be used like this:

The request will only be valid if role contains ADMIN or REVIEWER.

ModelsExist

Determine if all of the values in the input array exist as attributes for the given model class.

By default the rule assumes that you want to validate using id attribute. In the example below the validation will pass if all model_ids exist for the Model.

You can also pass an attribute name as the second argument. In the example below the validation will pass if there are users for each email given in the user_emails of the request.

Delimited

This rule can validate a string containing delimited values. The constructor accepts a rule that is used to validate all separate values.

Here's an example where we are going to validate a string containing comma separated email addresses.

Here's some example input that passes this rule:

This input will not pass:

Setting a minimum

You can set minimum amout of items that should be present:

Setting a maximum

Allowing duplicate items

By default the rule will fail if there are duplicate items found.

You can allowing duplicate items like this:

Now this will pass: 1,1,2,2,3,3

Customizing the separator

Skip trimming of items

Composite rules

The constructor of the validator accepts a validation rule string, a validate instance, or an array.

Passing custom error messages

The constructor of the validator accepts a custom error messages array as second parameter.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-validation-rules with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spatie/laravel-validation-rules contains the following files

Loading the files please wait ....