Answer the question
In order to leave comments, you need to log in
How to properly use unique rule in Laravel custom request classes?
It is necessary to process the field with the unique rule, except if an update occurs. That is, if some entity changes, check for uniqueness and throw an error if the field with this value already exists, but if the same model changes, then it turns out that it also falls under this rule and an error is thrown. How to fix it ?
Tried like this:
public function rules()
{
return [
'title' => "required|min:3,max:255|unique:audiobook_genres,id",
'slug' => "required|min:3,max:255|unique:audiobook_genres,id",
];
}
public function rules()
{
return [
'title' => "required|min:3,max:255|unique:audiobook_genres,id,".$this->id,
'slug' => "required|min:3,max:255|unique:audiobook_genres,id,".$this->id,
];
}
public function rules()
{
return [
'title' => "required|min:3,max:255|unique:audiobook_genres,title,".$this->title,
'slug' => "required|min:3,max:255|unique:audiobook_genres,slug,".$this->slug,
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question