0

Am working on a fullstack application whereby am parsing some data from the frontend to the backend via Curl. This works fine except when I json_Decode the data on the backend I keep getting a null response

Curl code that is parsing data to the bakend

   static function global_Curl_Med($url){

        $server =  'http://localhost/digital-apps-apis/public';

        $headers = ["Accept:application/json",
                    "Content-Type:application/json"
                    ];

        $data = [
            name => $data->name,
            phone => $data->phone,
            email => $data->email
        ]; 

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, ($server.'/'.$url));
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
        $response = json_decode(curl_exec($ch));

        curl_close($ch);

        return $response;
    }

Backend function whereby am consuming the data

 public function travel_letter_email(Request $request) {
        $ch = json_decode($request->all() , true);
       dd($ch->name);
   }
Martin
  • 547
  • 2
  • 11
  • 40

0 Answers0