PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

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

 April 19, 2022     laravel, laravel-5.8, laravel-validation, php, validation     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing