I make validation form which update user, and I have a problem. When I want to update only first name, show me validate error that email is already been taken, but I don't change email. So what can I do that not show validate error if I not change email ?
This is rules()
public function rules()
{
return [
'first_name' => 'min:3|max:20|regex:/^[a-zA-z-0-9]+$/u',
'last_name' => 'string|min:3|max:30|regex:/^[a-zA-z-0-9]+$/u',
'email' => 'email|unique:customers,email',
'phone_number' => 'min:9|max:9|unique:customers','phone_number'
];
}
view
<form action="{{ route('customers.update', ['customer' => $customer->id]) }}" method="POST" novalidate>
<div class="form-outline mb-4">
<input type="text" id="form4Example1" class="form-control" name="email"
value="{{ old('email', $customer->email) }}"/>
<label class="form-label" for="form4Example1">Email</label>
@error('email')
<span class="text-danger">
{{ $message }}
</span>
@enderror
</div
controller
public function update(CustomerRequest $request, $id)
{
Customer::updated($request->validated());
return redirect()->route('customers.index')->with('updateMessage', 'Customer data successfully updated');
}