Laravel update model with unique validation rule for attribute

后端 未结 18 2237
春和景丽
春和景丽 2020-11-27 12:45

I have a laravel User model which has a unique validation rule on username and email. In my Repository, when I update the model, I rev

18条回答
  •  广开言路
    2020-11-27 13:12

    For a custom FormRequest and Laravel 5.7+ you can get the id of your updated model like this:

    public function rules()
        {
            return [
                'name' => 'required|min:5|max:255|unique:schools,name,'.\Request::instance()->id
            ];
        }
    

提交回复
热议问题