Complex unique validation rule in Laravel

Laravel provides unique validation rule for check unique value on a given database table.

Ref : https://laravel.com/docs/5.1/validation#rule-unique

Syntax

unique:table,column,except,idColumn,whereColumn1,whereValue1,whereColumn2,whereValue2,…

Ex1. Validate unique value in given database table

Ex2. Validate unique value except given ID

In mostly used when update existing record.

Ex3. Gives id column name if primary key of table isn’t ‘id’.

Ex4. Adding additional where clauses for more complex condition

If company has tag list and want to check unique value,

If company has hierarchical folder list and want to check unique value per each node,

zemna

Programmer/Web/Mobile/Desktop

You may also like...

Leave a Reply