I'm trying to update an user and when the email is already taken it will give an error, except when it's your own email. Right now my code is:
$user = User::find($id);
$input['email'] = request('email');
$rules = array('email' => 'unique:users,email,'.$user->id);
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return back()->withInput()->withErrors(['email']);
}
This works perfectly fine, but now I want that it only gives an error if the email already exists AND from the found record the column 'function' = 'client', but I have no idea how to code this.