skip to Main Content

I have tried validating the user request like this:

$data = $request->validate([
    'fname' => 'nullable',
    'lname' => 'nullable',
    'gender' => 'required',
    'mobile' => 'required|unique:users,usr_name',
    'ncode' => 'nullable',
    'password' => 'required',
    'password_confirmation' => 'required',
]);

That the mobile filed value must be unique:users,usr_name but I do need to check that it is unique at members table as well (the mbr_mobile column):

unique:members,mbr_mobile

So how to combine these two rules at once?

2

Answers


  1. You can do it exact,y same way as for users table :

    $data = $request->validate([
            'fname' => 'nullable',
            'lname' => 'nullable',
            'gender' => 'required',
            'mobile' => 'required|unique:users,usr_name|unique:members,mbr_mobile',
            'ncode' => 'nullable',
            'password' => 'required',
            'password_confirmation' => 'required',
        ]);
    
    Login or Signup to reply.
  2. Just specifying the model name should work.

    'mobile' => 'required|unique:User|unique:Members',
    

    But you may specify the column name too.

    'mobile' => 'required|unique:User, mobile|unique:Member,mbr_mobile',
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search