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) {
$table->increments('id');
$table->string('task_name');
$table->text('task_description');
$table->unsignedBigInteger('project_id');
$table->unique(['task_name', 'project_id']);
$table->date('task_deadline');
$table->integer('weight')->unsigned();
$table->tinyInteger('completed')->unsigned()->default(0);
$table->date('date_completed')->nullable()->default(null);
$table->timestamps();
Note the highlighted line in lime. It defines columns those should be unique as a pair. To elaborate a little more, a user cannot insert same task name for a particular project id.

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:

......
$validator = Validator::make($request->all(), [
'task_name' => 'required|min:2|max:191|unique:tasks,task_name,NULL,NULL,project_id,' . $request->input('project_id'),
......

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