mazbaul / comp
Custom Laravel Validator For Composite Key Validation
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/mazbaul/comp
Requires
- php: ^7.1.3
- illuminate/support: 5.*|^6.0
- illuminate/validation: 5.*|^6.0
Requires (Dev)
- bossa/phpspec2-expect: ^3.0
- phpspec/phpspec: ^5.0
This package is auto-updated.
Last update: 2025-09-27 18:27:43 UTC
README
This package contains composite key validation rule for Laravel, that allows for validation of multi-column UNIQUE indexes.
Installation
Install the package through Composer. On the command line:
composer require mazbaul/comp
Configuration
Add the following to your providers array in config/app.php:
'providers' => [ // ... Mazbaul\Comp\CompServiceProvider::class, ],
Usage
Use it like any Validator rule:
$validator = Validator::make($request->all(), [ "<field1>" =>'required|composite_unique:<table>,<field1>,<field2>', ]);
See the Validation documentation of Laravel.
Ignore existing row (useful when updating)
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, ]);
License
MIT