Ad

Laravel 5.2 Validation Check If Value Is Not Equal To A Variable

- 1 answer

In my instance one user is inviting another I would like to check if the user they are inviting is not themselves.

Thus I have two variables incomming email and user->email

$this->validate($request, [
            'email' => 'required|email',
        ]);

How can I add that validation rule to the validation call?

Ad

Answer

You can use not_in, which allows you to specify a list of values to reject:

$this->validate($request, [
    'email' => 'required|email|not_in:'.$user->email,
]);
Ad
source: stackoverflow.com
Ad