thedavefulton / laravel-exclusive-validation-rules
Two additional validation rules for use with the Laravel framework
Requires
- php: ^7.1
- illuminate/support: 5.8.*
Requires (Dev)
- orchestra/testbench: 3.8.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-04-25 11:49:54 UTC
README
This package was born out of a need to ensure that for a set of inputs exactly 1 was received. Using existing validation rules could ensure that at least 1 or no more than 1 would be received, but there wasn't a succinct way of guaranteeing exactly one.
As such, two rules were implemented. The first, require_exclusive
, ensures that exactly 1 of the inputs will be present. The second, optional_exclusive
, allows for none of the inputs to be present but if any are present there must be exactly 1.
Installation
You can install the package via composer:
composer require thedavefulton/laravel-exclusive-validation-rules
The package is configured to use Laravel's automatic discovery. However, you can manually register the service provider in the app/config.php
file:
'providers' => [ // Other Service Providers Thedavefulton\ExclusiveValidationRulesServiceProvider::class, ],
Usage
These rules may be used like any standard validation rule.
$attributes= $request->validate([ 'input1' => 'required_exclusive:input2', 'input2' => 'required_exclusive:input1', ]); $attributes= $request->validate([ 'input1' => 'optional_exclusive:input2', 'input2' => 'optional_exclusive:input1', ]);
They can also be extended to n inputs
$attributes= $request->validate([ 'input1' => 'required_exclusive:input2,input3,input4', 'input2' => 'required_exclusive:input1,input3,input4', 'input3' => 'required_exclusive:input1,input2,input4', 'input4' => 'required_exclusive:input1,input2,input3', ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email thedave@thedavefulton.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.