4

I have a users table and two columns that are: email and phone. In my register and login controller, I wanna make a field unique in both email and phone columns.

$data = request()->validate([
   'login' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
   'password' => ['required', 'string', 'min:8', 'confirmed'],
]);

This is my code and it only checks email column to ensure the value of login field doesn't exist there. How can I change this rule to check both email and phone columns?

STA
  • 30,729
  • 8
  • 45
  • 59
Ali Raghebi
  • 205
  • 2
  • 6

1 Answers1

1

Just make another ‌‌‌‌‌rule‌‌‌‌‌‌‌:‌‌‌‌‌‌‌‌‌

$data = request()->validate([
   'login' => ['required', 'string', 'email', 'max:255', 'unique:users,email','unique:users,phone'],
   'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
sajad abbasi
  • 1,988
  • 2
  • 22
  • 43
STA
  • 30,729
  • 8
  • 45
  • 59