Laravel unique request update

Ive read some things about this on laracasts and Stackoverflow.
I have an update function with validation:
public function update(Customer $customer, StoreCustomer $request)
{
    $customer->update($request->validated());
    exit();
}
And the validation rules:
 public function rules()
{
    return [
        'code'  => 'required|unique:customers,code',
    ]
}
Now I tried to add a 3rd argument after the unique, so if it would exist it would continue. I tried it like this:
 public function rules(Customer $customer)
 {
    return [
        'code'  => 'required|unique:customers,code,'.$customer->code,
    ]
}
but that doesn't seem to do anything. It seems to work if you do the validation in my controller itself, but this looks way cleaner. Any solutions?

Комментарии

Популярные сообщения из этого блога

Unable to construct Application instance [duplicate]

What is considered 'insulting a Muslim'? And is it a sin? If so, is it a minor or major scene?