Reputation: 35
I have created a function for validation rule in add/edit "localities"
I have checked the name field as unique in "localities" table.
I have one more field "is_deleted" in localities table. If the "is_deleted" field value is 1, then it didn't ask the validation (i.e) No need to ask "Name is already in use".
public function rules()
{
return [
'name' => ['required', 'unique:localities'],
'city_id' => ['required']
];
}
How to create a custom rule for this condition
Upvotes: 1
Views: 151
Reputation: 34914
You can exclude/ignore by adding column name and id,like
public function rules()
{
return [
'name' => ['required', 'unique:localities,name,1,is_deleted'],
'city_id' => ['required']
];
}
Upvotes: 4