How to prevent insert email if already exist with specific id in laravel?

◇◆丶佛笑我妖孽 提交于 2019-11-29 15:16:57

Forcing A Unique Rule To Ignore A Given ID

You can specify an ID to be ignored as the optional third parameter. Furthermore, if your table uses a primary key column name other than id, you may specify it as the optional fourth parameter

'email' => "unique:{$table},{$field},{$user->id},{$idField}"

So in your case, it'd be as follows

'email' => "unique:email_list,email,{$user->id},user_id'

It is against of exist rule.
First of all, the exist rule check based on the condition the fields is avail or not.
I think, if we used it as opposite then it is useful for you.

Ex:-

     'email' => 'exists:email_list,email,user_id,!102'

i.e.,

     'email' => 'exists:email_list,email,user_id,!'. $user_id        

otherwise,

     'email' => 'exists:email_list,email,user_id,!'. Input::get(user_id)

while using Input & import the

    use Illuminate\Support\Facades\Input;        

and change message content
Please try these and reply what happened.. or is it work for you..?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!