Lê Trọng
Lê Trọng

Reputation: 1

Laravel Validator: How to check exists rule in multiple column database

I have checked my credentials with an authenticator and want to check if the username exists in the phone or email column, but I don't know how.

Thanks for any ideas

For example:

$rules = [
        'email' => 'required|exists:users,[email, phone]'
    ];

    $messages = [
        'email.exists' => '......',
    ];

    Validator::make($request->all(), $rules, $messages)->validate();

Upvotes: 0

Views: 176

Answers (1)

Syahnur Nizam
Syahnur Nizam

Reputation: 91

Try this instead

$rules = [
    'email' => 'required|exists:users,email',
    'phone' => 'required|exists:users,phone',
];

$messages = [
    'email.exists' => '...',
    'phone.exists' => '...',
];

Upvotes: 1

Related Questions