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