My validator returns the errors in the request.
I would like to check if the variable I save my errors has the email error to then return the correct response.
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 get:
message: "Undefined property: stdClass :: $ email