Captcha on Controller Laravel

0

Good afternoon guys,

I'm trying to implement Google Captcha in my controller, but the 500 error in the request

The code works until return 2;

From here you attempt to run the 500 error

    public function enviar(Request $request){
  /*
  error codes
  1 - Algum campo está vazio
  2 - Captcha não verificado
  3 - Google acha que é um Robo
  */
  // captcha
  $captcha = $request->input('g-recaptcha-response');
  // // Se o captcha nao for verificado
  if(!$captcha)
  // retorna erro 2
    return 2;
  $secret_key = "6Lc8v0MUAAAAABZCm2IzGpbvIEXA5taSiAgNf";
  $ip = $request->ip();
  $callback = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret_key.'&response='.$captcha.'&remoteip='.$ip);
  $arr = json_decode($resp,TRUE);
  // // se o google retornar false
  if(!$arr['success'])
  // retorna erro 3
    return 3
  // Enviando email
  Mail::to('email')->send(new ContatoEmail($request));
  return 4;
}
    
asked by anonymous 01.02.2018 / 15:40

0 answers