Catagory : Validation Title : Validate Uniqueness of multiple columns |
---|
This is aimed at cases where you have a set of columns which have been defined as unique. Following is the table structure
Schema::create('tasks', function (Blueprint $table) {
Now, to validate the data through Laravel controller, assume that user inputs the task name. I am validating the task_name field and I have received my project_id from the form. Here is the code snippet from the controller:
......
From LARAVEL documentation, this is stated as unique:table,column,except,idColumn. This is pretty confusing and I believe there are multiple typo and misleading information in official documentation. Firstly the format should be unique:table,column,except,idColumn. Official documentation states that: "If the column option is not specified, the field name will be used" Secondly it does not specify that you have put the value of your target pair (project_id in this case) and separated by a comma unique:table,column,except,id,Column,Column_value Thirdly You can stack more columns, means you can validate the uniqueness of a group of columns, you can do like this unique:table,column_1,null,null,column2,column2_value,,null,null,column3,column3_value |