hi i have laravel project and im using custom request this is my request code
public function rules()
{
if($this->method() == 'POST' and $this->ajax())
{
return [
'id' => 'integer|min:1|unique:archive_categorys',
'archive_category_name' => 'max:50|min:1|unique:archive_categorys',
'archive_category_id' => 'nullable|integer|min:1|max:'.Archive_category::max('id'),
'archive_category_max' => 'nullable|integer|min:1|',
'archive_category_plus_value' => 'nullable|integer|min:1|',
'image' => 'nullable|image|mimes:jpg,jpeg,gif,png|max:2048',
];
}
elseif($this->method() == 'PATCH' )
{
return [
'id' => 'required|min:1|unique:archive_categorys,id,'.$this->id,
'archive_category_name' => 'required|max:50|min:1|unique:archive_categorys,archive_category_name,'.$this->id,
'archive_category_id' => 'nullable|min:1|max:'.Archive_category::max('id'),
'archive_category_max' => 'nullable|integer|min:1|',
'archive_category_plus_value' => 'nullable|integer|min:1|',
'image' => 'nullable|image|mimes:jpg,jpeg,gif,png|max:2048',
];
}
else
{
return false;
}
}
now my problem with method patch
'id' => 'required|min:1|unique:archive_categorys,id,'.$this->id,
now if i tried to change archive_categorys with id 1 to 2
if there is no archive_categorys with id 2 its will update successfully but if there is anther archive_categorys with id 2 its will pass and get error 1062 Duplicate entry
so how can i check unique value in laravel when update thanks