title: How can I assign 'g-recaptcha-response' to a variable? With 'g-recaptcha-response' being a parameter inside $request->validate([])
body: <blockquote>
    <p>So what i want is to put 'g-recaptcha-response' in a variable to be able to use it in my condition to verify recaptcha but I haven't been able to do this. Is there any way to only use recaptcha field from the array inside validate() because my code as it is, redirects me back to homepage. It goes straight to else statement.</p>
  </blockquote>
  
  <pre><code> public function contactanospost(Request $request){     
           $request-&gt;validate([                       
             'nombre' =&gt; 'required|distinct',
             'telefono'=&gt; 'required|telefono',
              'correo' =&gt; 'required|email',
             'mensaje' =&gt; 'required',
          'g-recaptcha-response' =&gt; 'required|captcha',
  
           ]);
           if(POST['g-recaptcha-response']){             /*here I am trying to 
                                                     check with a condition if recaptch was really validated once the form is submitted */
             $token= POST['g-recaptcha-response'];
            $client = new Client();
            $response = $client-&gt;post('https://www.google.com/recaptcha/api/siteverify', [
  
            'form_params' =&gt; array('secret' =&gt; 'mycaptchakey',
            'response'=&gt; $token                       /*Checking with google parameters for recaptcha if the user was indeed verified */
          )
        ]);                                     
        $resultados = json_decode($response-&gt;getBody()-&gt;getContents()); //decode with json
        if($resultados-&gt;success){ /*if this was a success then return a page with parameters from google recaptcha such as: secret, response, remote ip.*/
          dd($resultados); /*show the results from verified user and that recaptcha is working*/
  
     $contactanos = Contactanos::create($request-&gt;all());/* and create all fields for model Contactanos*/
     Mail::to('some@mail')-&gt;send(new enviacorreo($contactanos)); /* since it is a contact form then send all the information to some mail*/
  
       \Session::flash('flash_message','Tu mensaje ha sido enviado!'); /* send a message with "email delivered" verification*/
        return redirect()-&gt;back();
        }
        else{
          \Session::flash('flash_message','Robot');
          return redirect('/');
        }
  
  
           }
           else{
             return redirect('/');
           }
  
  
  
  
  
  
  
  
  
   }
  </code></pre>
  
  <blockquote>
    <p>I'm now able to access request properties using input() what got me confused were my if statements. The real problem is that after: </p>
  </blockquote>
  
  <pre><code>$resultados = json_decode($response-&gt;getBody()-&gt;getContents());
  </code></pre>
  
  <blockquote>
    <p>next if statement is not getting the expected success but instead it goes straight to else with robot message:</p>
  </blockquote>
  
  <pre><code> else{
      \Session::flash('flash_message','Robot');
      return redirect('/');
    }
  </code></pre>