Download the PHP package rtfmfm/uniquewith-validator without Composer
On this page you can find all versions of the php package rtfmfm/uniquewith-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rtfmfm/uniquewith-validator
More information about rtfmfm/uniquewith-validator
Files in rtfmfm/uniquewith-validator
Package uniquewith-validator
Short Description Custom Laravel Validator for combined unique indexes
License MIT
Homepage https://github.com/rtfmfm/uniquewith-validator
Informations about the package uniquewith-validator
unique_with Validator Rule For Laravel
This package contains a variant of the validateUnique
rule for Laravel, that allows for validation of multi-column UNIQUE indexes.
Documentation for older versions
Installation
Install the package through Composer. On the command line:
Configuration
Add the following to your providers
array in config/app.php
:
Usage
Use it like any Validator
rule:
See the Validation documentation of Laravel.
Specify different column names in the database
If your input field names are different from the corresponding database columns, you can specify the column names explicitly.
e.g. your input contains a field 'last_name', but the column in your database is called 'sur_name':
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
To specify a custom column name for the id, pass it like
If your id is not numeric, you can tell the validator
Add additional clauses (e.g. when using soft deletes)
You can also set additional clauses. For example, if your model uses soft deleting then you can use the following code to select all existing rows but marked as deleted
Soft delete caveat:
In Laravel 5 (tested on 5.5), if the validation is performed in form request class, field deleted_at is skipped, because it's not send in request. To solve this problem, add 'deleted_at' => null to Your validation parameters in request class., e.g.:
Specify specific database connection to use
If we have a connection named some-database
, we can enforce this connection (rather than the default) like this:
Example
Pretend you have a users
table in your database plus User
model like this:
Now you can validate a given first_name
, last_name
combination with something like this:
License
MIT
All versions of uniquewith-validator with dependencies
illuminate/support Version ^5.5|^6.0|^7.0|^8.0|^9.0
illuminate/validation Version ^5.5|^6.0|^7.0|^8.0|^9.0