Is there any way to get original data in request? I mean, in my case I want to validate updating user's in the form. I want the email to be unique on emails in database except on the email that user wrote to the form.
3 Answers
Laravel already has a validation rule for this, you can add an id of the user to ignore to your unique validator.
'email' => [
'required',
Rule::unique('users')->ignore($currentUser->id),
]
Comments
You can do it liks this:
'email' => 'unique:users,email,'.$user->id
The user id will allow you to keep updating the record but maintain the unique constraint on email. You don't need a hidden input field for $user->id btw.
1 Comment
Epsilon47
I do because form I am updating is binded like so:
{!! Form::model($customerAddress, ['route' => 'user.update', 'class' => 'form form-horizontal form-user-data']) !!} and I cannot access $this->user in the request.