I am very new to Laravel, and I am creating an "update profile" page. All is well, except saving my profile. Since I have declared that email must be unique - I will get an error. Makes perfect sense. I have been reading through this SO post about what I think is the same problem.
I am using form requests to handle my validation:
public function rules()
{
return [
'name' => 'required',
'email' => 'required|unique:users,email,' . Auth::user()->id,
...
]
}
My controller:
public function store(UpdateAccountRequest $request)
{
$input = $request->all();
$user = new User();
$user->name = $input['name'];
$user->email = $input['email'];
if ($user->save()) {
...
}
...
}
It looks like I am getting the error on the mysql side:
Integrity constraint violation: 1062 Duplicate entry 'name@email.com' for key 'users_email_unique'
Coming from CodeIgniter, in the past I would have a hidden field with the user Id or something and check if the user id was editing their own account. If so, validation would pass. I'm not sure about the best way to go about this.
Thank you!