Download the PHP package monooso/apposite without Composer
On this page you can find all versions of the php package monooso/apposite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monooso/apposite
More information about monooso/apposite
Files in monooso/apposite
Package apposite
Short Description Conditionally apply validation rules in Laravel
License MIT
Homepage https://github.com/monooso/apposite
Informations about the package apposite
Apposite
About Apposite
Apposite makes it easy to conditionally apply Laravel validation rules, even when you don't have access to the validator instance.
Requirements and installation
Select the appropriate branch for your version of Laravel.
Branch | Laravel Versions | PHP Version |
---|---|---|
1.x | ^6.0 |
^7.2 |
2.x | ^7.0 |
^7.2.5 |
3.x | ^8.0 |
^7.3 |
4.x | ^8.0 |
^8.0 |
Install Apposite using Composer:
Usage
Apposite provides three custom Laravel validation rules:
ApplyWhen
ApplyUnless
ApplyMap
ApplyWhen
Use ApplyWhen
to apply one or more validation rules when a condition is met. For example, validate the email
field if the contact_method
is "email".
The ApplyWhen
constructor expects two arguments:
- A conditional, which determines whether the validation rules are applied. This may be a boolean value, or a closure which returns a boolean.
- The validation rules to apply if the conditional evaluates to
true
. The may be in any format recognised by the Laravel validator.
For example:
Add the ApplyWhen
rule to your validation rules array in the normal way.
ApplyUnless
ApplyUnless
is the opposite of ApplyWhen
. Use it to apply one or more validation rules when a condition is not met.
For example:
Refer to the ApplyWhen
documentation for full usage instructions.
ApplyMap
Use ApplyMap
when you need to choose between different sets of validation rules. For example, when validating that the chosen delivery_service
is offered by the chosen delivery_provider
.
The ApplyMap
constructor expects two arguments:
- The "key" value, which determines which rules to apply (if any). For example, "fedex".
- A "map" of keys to validation rules. The validation rules may be in any format recognised by the Laravel validator.
License
Apposite is open source software, released under the MIT license.