Tuesday, April 19, 2022

[FIXED] How to add two unique validation for one input

Issue

I'm trying to validate an input like this:

$validatedPhone = $request->validate([
        'user_input' => 'required|unique:users,user_name|regex:/^09\d{9}$/|max:11|min:11',
]

Now I need to say that the value of this input does not exist at another table which is members table and member_mobile column.

But I have already defined a unique rule for the users table with user_name column.

So how to define two unique rules for two different tables for validating one input?


Solution

Just add another rule as shown below

 $validatedPhone = $request->validate([
        'user_input' => 'required|unique:users,user_name|unique:members,member_mobile|regex:/^09\d{9}$/|max:11|min:11',
    ]


Answered By - Donnicias
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.