2017 © Pedro Peláez
 

library composite-unique-validator

Laravel 5 composite unique validator

image

ahkmunna/composite-unique-validator

Laravel 5 composite unique validator

  • Tuesday, January 31, 2017
  • by ahkmunna
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 25 % Grown

The README.md

Composite Unique Validator

A muti-column unique validation extension with exception for Laravel 5.*, (*1)

Installation

Install the package through Composer., (*2)

On you project directory run the composer require command from the Terminal:, (*3)

composer require ahkmunna/composite-unique-validator

Now add the service provider to your config/app.php file. Add this line to the providers array:, (*4)

ahkmunna\validator\CompositeUniqueValidatorServiceProvider::class

Translations

Run this command to move the translation file, (*5)

php artisan vendor:publish

Error messages

Add this method in your validation request class, (*6)

public function messages()
{
    return [
        'email.composite_unique' => trans('compositeUniqueValidator::compositeUniqueValidator.composite_unique'),
    ];
}

Now you're ready to start using the validator in your application., (*7)

Use case 1

Like any laravel validation rules:, (*8)

$rules = array(
    'field_name' => 'composite_unique:table, unique_column_1, unique_column_2, unique_column_3',
);

Use case 2

Pass a value or Check uniqueness with a field that not in current form request:, (*9)

$rules = array(
    'field_name' => 'composite_unique:table, unique_column_1, unique_column_2:4, unique_column_3',
);

unique_column_2 is passed with a value so the validator will ignore the form request value and compare the field with the given value, It is useful sometimes, you can give a field name that not exist in the form request but in the database table., (*10)

Use case 3:

Check uniqueness with exception:, (*11)

$rules = array(
    'field_name' => 'composite_unique:table, unique_column_1, unique_column_2, unique_column_3, 1',
);

The last parameter is a primary key of the table that row will be ignored. Useful for update operation., (*12)

+++ Thank You +++

The Versions

31/01 2017

dev-master

9999999-dev https://github.com/ahkmunna/compositeUniqueValidator

Laravel 5 composite unique validator

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator

31/01 2017

1.0.0

1.0.0.0 https://github.com/ahkmunna/compositeUniqueValidator

Laravel 5 composite unique validator

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator