Próbuję zrobić update na użytkowniku. Gdy mam formularz do update to jest wypełniony aktualnymi danymi. Do tego robię walidację i tutaj jest problem bo jak aktualizuję i nie zmienię email i numeru telefonu to pojawiał się błąd że taki email lub numer już istnieje. Dlatego dodałem taki kod Rule::unique('customers')->ignore($this->customer)
ale teraz gdy wpiszę email innego usera to nie pojawia się błąd. W skrócie chodzi o to żeby przy update gdy nie chcę zmieniać email nie pojawiał się błąd walidacji, ale pojawiał się gdy zmienię email na taki który juz istnieje w bazie.
Oto mój kod:
class CustomerRequest extends FormRequest
{
public function rules()
{
return [
'first_name' => 'min:3|max:20|regex:/^[a-zA-z-0-9]+$/u',
'last_name' => 'min:3|max:30|regex:/^[a-zA-z-0-9]+$/u',
'email' => 'email', Rule::unique('customers')->ignore($this->customer),
'phone_number' => 'min:9|max:9', Rule::unique('customers')->ignore($this->customer)
];
}
Kontroler
public function update(CustomerRequest $request, Customer $customer)
{
$data = $request->validated();
$customer->fill($data);
$customer->save();
return redirect()->route('customers.index')->with('updateMessage', 'Customer data successfully updated');
}