mazbaul/comp is a Laravel package for custom laravel validator for composite key validation.
It currently has 3 GitHub stars and 2 downloads on Packagist.
Install it with composer require mazbaul/comp.
Discover more Laravel packages by mazbaul
or browse all Laravel packages to compare alternatives.
Last updated
This package contains composite key validation rule for Laravel, that allows for validation of multi-column UNIQUE indexes.
Install the package through Composer. On the command line:
composer require mazbaul/comp
Add the following to your providers array in config/app.php:
'providers' => [
// ...
Mazbaul\Comp\CompServiceProvider::class,
],
Use it like any Validator rule:
$validator = Validator::make($request->all(), [
"<field1>" =>'required|composite_unique:<table>,<field1>,<field2>',
]);
See the Validation documentation of Laravel.
You can also specify a row id to ignore (useful to solve unique constraint when updating)
This will ignore row with id 2
$validator = Validator::make($request->all(), [
"<field1>" =>'required|composite_unique:<table>,<field1>,<field2>,ignore-<primaryKey>-'.$id,
]);
MIT