0

I have a validation class:

    class AnalyseRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        'code' => 'required|code_format|unique:analyses',
    }
}

The code field stores the code, which must be unique. There is a template where this code is displayed for editing. I edit other fields, I do not touch the code. I keep my form. Then this rule is triggered. Tell me please, how can I set up the validator so that it works correctly when this value is edited to a new one?

tirael8
  • 213
  • 4
  • 14
  • This issue is similar to this https://stackoverflow.com/questions/22405762/laravel-update-model-with-unique-validation-rule-for-attribute – Leo Rams Jun 27 '18 at 13:20

1 Answers1

0

Use:

'code' => 'required|code_format|unique:analyses,code,'.$this->id,
Jinal Somaiya
  • 1,931
  • 15
  • 29