0
My Validator returns the existing errors in the request.
I would like to check if in the variable I save my errors has the error email to return the correct answer.
I tried something like:
public function register(Request $request)
{
$errors = $this->validator($request->all())->errors();
if(count($errors))
{
$obj = json_decode($errors);
if($obj->email){
return response(['errors' => 'Este email já está cadastrado no sistema, tente outro.'], 401);
}else{
return response(['errors' => $errors],401);
}
}
event(new Registered($user = $this->create($request->all())));
return response(['mensagem' => "Usuário cadastrado com sucesso!"]);
}
However, I do receive:
message: "Undefined Property: stdClass::$email