Laravel update model with unique validation rule for attribute

后端 未结 18 2170
春和景丽
春和景丽 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:34

    or what you could do in your Form Request is (for Laravel 5.3+)

    public function rules()
        {
            return [
    
                'email' => 'required|email|unique:users,email,'.$this->user, //here user is users/{user} from resource's route url
                   ];
        }
    

    i've done it in Laravel 5.6 and it worked.

提交回复
热议问题