Giter Site home page Giter Site logo

gbrits / compositeuniquevalidator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahkmunna/compositeuniquevalidator

0.0 0.0 0.0 4 KB

A muti-column unique validation extension with exception for Laravel 5.*

License: MIT License

PHP 100.00%

compositeuniquevalidator's Introduction

Composite Unique Validator

A muti-column unique validation extension with exception for Laravel 5.*

Installation

Install the package through Composer.

On you project directory run the composer require command from the Terminal:

composer require ahkmunna/composite-unique-validator

Now add the service provider to your config/app.php file. Add this line to the providers array:

ahkmunna\validator\CompositeUniqueValidatorServiceProvider::class

##Translations Run this command to move the translation file

php artisan vendor:publish

##Error messages Add this method in your validation request class

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

Now you're ready to start using the validator in your application.

###Use case 1 Like any laravel validation rules:

$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:

$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.

###Use case 3: Check uniqueness with exception:

$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.

####+++ Thank You +++

compositeuniquevalidator's People

Contributors

ahkmunna avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.