xxxxxxxxxx
'mobile_no'
=> 'unique:users,mobile_no,NULL,id,country_id,'.request('country_id');
xxxxxxxxxx
[
'column_1' => 'required|unique:TableName,column_1,' . $this->id . ',id,colum_2,' . $this->column_2
]
xxxxxxxxxx
'name' => 'unique:table,field,NULL,id,field1,value1,field2,value2,field3,value3'
xxxxxxxxxx
'exam_category_id' => Rule::unique('exams')->where(function ($query) use ($request) {
return $query->where('exam_name', $request->exam_name)
->where('exam_year', $request->exam_year)
->where('student_id', $request->student_id);
})
xxxxxxxxxx
$messages = [
'data.ip.unique' => 'Given ip and hostname are not unique',
];
Validator::make($data, [
'data.ip' => [
'required',
Rule::unique('servers')->where(function ($query) use($ip,$hostname) {
return $query->where('ip', $ip)
->where('hostname', $hostname);
}),
],
],
$messages
);
xxxxxxxxxx
'name' => 'required|max:150|unique:course_lessons,name,NULL,id,course_id,' . request('course_id'),
"<input_filed_name>" => "valiadtionRule"|"ValidationRule"|"unique:<tableName>,<validateableField>,<ignoreableID>,<tablePrimaryKey>,<column1>,<column1Value>,<column2>,<column2Value>"
xxxxxxxxxx
// in my case, just add more unique rule
'phone1' =>'string|unique:tbl_users,phone1|unique:tbl_users,phone2|different:phone2|min:2',
'phone2' =>'string|unique:tbl_users,phone2|unique:tbl_users,phone1|different:phone1|min:2',
xxxxxxxxxx
public function rules()
{
return [
'column_1' => 'required|unique:TableName,column_1,' . $this->id . ',id,colum_2,' . $this->column_2 . ',colum_3,' . $this->column_3,
];
}
xxxxxxxxxx
public function rules(): array
{
return [
'date' => [
'required',
'unique:expenses,date',
Rule::unique('expenses', 'date')->where('user_id', $this->input('user_id')),
],
];
}
public function messages()
{
return [
'date.unique' => 'Expense for selected user on selected date already exists.',
];
}