This package adds seven new form request validations to your Laravel application that allows you to prohibit fields the same way as you usually require them.
You can install this package via composer using this command:
composer require ljsystem/laravel-prohibited
The package will automatically register itself.
After installing the package you can use the new rules the same way you would use Laravels official validation rules.
$request->validate([
'vehicle' => 'required|string|in:car,van,truck,bus,motorcycle',
'speeding' => 'prohibited',
'convertible' => 'prohibited_if:vehicle,motorcycle|integer',
'helmet' => 'prohibited_unless:vehicle,motorcycle|bool',
'hat' => 'prohibited_with:helmet,convertible|bool',
'sunglasses' => 'prohibited_with_all:helmet,helmet_has_visor|bool',
'helmet_has_visor' => 'prohibited_without:helmet|bool',
'helmet_visor_color' => 'prohibited_without_all:helmet,helmet_has_visor|string|in:clear,tinted',
]);
- Prohibited
- Prohibited If
- Prohibited Unless
- Prohibited With
- Prohibited With All
- Prohibited Without
- Prohibited Without All
The field under validation must not be present in the input data, regardless of it's value.
The field under validation must not be present if the anotherfield field is equal to any value.
The field under validation must note be present unless the anotherfield field is equal to any value.
The field under validation must not be present only if any of the other specified fields are present.
The field under validation must not be present only if all of the other specified fields are present.
The field under validation must not be present only when any of the other specified fields are not present.
The field under validation must not be present only when all of the other specified fields are not present.
The package comes with English and Swedish translations out of the box. If you wish to add translations for your own language you publish the translations to your applications resource directory by running the following command:
php artisan vendor:publish --provider="Ljsystem\Prohibited\ProhibitedServiceProvider"
This will result in the following file structure:
.
└── resources
└── lang
└── vendor
└── prohibited
├── en
│ └── validation.php
└── sv
└── validation.php
You can now copy either the English or Swedish validation.php
and translate it into your prefered language. Feel free to create a Pull Request if you would like to get your translations included in the package.
You can run the tests with:
vendor/bin/phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.