felixkiss / uniquewith-validator

Custom Laravel Validator for combined unique indexes
MIT License
389 stars 129 forks source link

How to allow update if I have more then one unique_with? #89

Closed shone83 closed 5 years ago

shone83 commented 6 years ago

This is my AddMembersEditRequest.php:

public function rules()
{
    return [
        'name'          => 'required',
        'last_name'     => 'required',
        'social_number' => 'nullable|unique:add_members',
        'telephone_1'   => 'nullable|unique_with:add_members, name, last_name',
        'street'        => 'nullable|unique_with:add_members, name, last_name, number'
    ];
}

but when I want to update it gives me message: This combination of street, name, last name, number already exists.

this is update method in controller:

public function update(AddMembersEditRequest $request, $id)
{
    $member = AddMember::findOrFail($id);

    $member->update($request->all());

    $url = $request->only('redirects_to');

    return redirect()->to($url['redirects_to']);
}

how to ignore unique on update?