问题
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?
回答1:
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,
]);
回答2:
You can use different:field according to the laravel Document
For instanse in your requests validation:
public function rules()
{
return [
'from' => 'required',
'to' => 'required|different:from',
'action' => 'required',
'access' => 'required'
];
}
These two from and to should be different(not same).
来源:https://stackoverflow.com/questions/34842487/laravel-5-2-validation-check-if-value-is-not-equal-to-a-variable