I have create a validation request file on request folder. It working fine in new insert. But when i update, it's not working also i pass the unique $id but not working.
a. Resource controller update method
public function update(KlassNameRequest $request, $id)
{
$validated = $request->validated();
KlassName::where('id', $id)->update($validated);
}
b. Validation code
public function rules()
{
return [
'name' => 'required|unique:klass_names|max:128,' . $this->id,
'ref' => 'required|unique:klass_names|numeric|between:1,999,' . $this->id,
'seat_quota' => 'required|numeric|between:1,9999',
'division' => 'required',
'semester' => 'required',
];
}
This message shows me when i update
CodePudding user response:
Just try this one
'name' => ['required','max:128',Rule::unique('klass_names')->ignore($this>id)],
'ref'=> ['required', 'numeric','between:1,999',Rule::unique('klass_names')->ignore($this>id)],
Hope it will solve the problem