Support the ongoing development of Laravel.io →
Requests Forms Validation
Last updated 1 year ago.
0

Is this what you want? 1 - If during the edit, the user has changed their name, then include the unique validation 2 - If during the edit, the user has not changed their name, then don't include the unique validation

The document references an "except" on the unique validation. Would the following work?

public function update($id, Request $request) {
        $this->validate($request, [
            'name' => 'required|unique:customers,name,except,' . $id . '|min:3'
        ]);
        $customer = Customer::findOrFail($id);

        $customer->update($request->all());
        return redirect('customers/'.$id);
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

crag crag Joined 10 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.