欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Laravel 5.2 validation check if value is not equal to a variable

 

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?


正确答案 

6down voteaccepted

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,
]);

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?


普通分类: