phpMick
217
14
General

Forcing A Unique Rule To Ignore A Given ID in Form Request

Posted 10 months ago by phpMick

Can someone please remind me how to do this in L5.5?

I am editing a user, the email field is unique.

Like this:

Validator::make($data, [
    'email' => [
        'required',
        Rule::unique('users')->ignore($user->id),
    ],
]);

but in a form request.

This is what I have:

 return [
                'name'=>'required',
                'email'=>'required|email|unique:users,email'
}

It looks like I need the $user->id but I don't have the $user in my form request.

Pretty sure I have done this before.

Mick

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.