Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel validation : Check Exist in two tables

I have the following validation, Where i am trying to check the email in two tables :

$validator = Validator::make($request->all(),
[
    'email' => "exists:users,email|exists:user_company,company_email"
]);

But it only works for one table and that is the users table.

Is there anyway around it ?

like image 637
Gammer Avatar asked Sep 15 '25 12:09

Gammer


1 Answers

There is option to add custom validation rules in laravel. Read about this here Laravel Custom Rules

For example:

$validator = Validator::make($request->all(), [
            'email' => ["exists:users,email", function($attribute, $value, $fail) {
                    /* Custom Validation code */
                },],
        ]);
like image 174
Lovepreet Singh Avatar answered Sep 18 '25 06:09

Lovepreet Singh