krishna972076's avatar

Undefined property: stdClass::$data error

Hello experts,

can anyone please help me what i am doing wrong here?

Getting error like Undefined property: stdClass::$data error


public function login(Request $request) {
    //
        $input = Request::input();
       

        $url = $this->api_url . 'login'; // hit login function
       // dd($url);
        if (isset($input) && !empty($input)) {

            $data = [
                "email" => $input['email'],
                "password" => $input['password']
            ];
           // dd($data);
            $res = $this->hit_method('', $url, $data); // hit login API

            $res = json_decode($res);

          //  dd($res);
         

            if (!empty($res)) {
                if ($res->code == 200) {
                    $userdata = $res;

                    $sesdata = ["id" => $userdata->data->id, "comp_id" => $userdata->data->company_id, "name" => $userdata->data->name, "email" => $userdata->data->email, "token" => $userdata->data->auth_token, "csrf_tokan" => csrf_token()];
                    Session()->put('userdata', $sesdata); // set userdata into session
                    return Redirect::to('/candidate-pipeline');
                } else {

                    return redirect()->back()->with('message', "error");
                }
            }
        }
    }

0 likes
3 replies
tykus's avatar

The JSON returned from $this->hit_method('', $url, $data); does not have a data key.

krishna972076's avatar

@tykus

Here is the hit_method.


public function hit_method($token = '', $url, $postData = [], $type = 'POST') {
        //dd($postData);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, ["token: " . $token]);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_HEADER, 1);
        $response = curl_exec($curl);                
       // dd($response);
        $result = [];
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);        
        $code = ['code' => curl_getinfo($curl, CURLINFO_HTTP_CODE)];
       // dd($code);
        $body = substr($response, $header_size);                     
        $result = array_merge($code, (array) json_decode($body));        
        //dd($curl);
        return json_encode($result);
       // curl_close($curl);
    }

tykus's avatar

Does this prove or disprove that there is a data key in the response?

Please or to participate in this conversation.