waleed bin khalid
waleed bin khalid

Reputation: 112

ErrorException in dataController.php line 98: Undefined property: stdClass::$id Laravel

I am trying to the the "id" value from a JSON request. But i am getting this error Undefined property: stdClass::$id Laravel.

$data = json_decode($request->getContent());
foreach ($data->data as $data){
            $id = $data->id;


  $modsyPrice = floor($data->modsyPrice);
}

Here is my Json:

{"data":{"0":{"ID":"1","Name":"3 Piece Roundabout Candle Holders","Url": 

"http://url","ModsyStatus":"0","weRplayStatus"

:"0", "ModsyPrice" :"39.95", "weRplayPrice":"39.95","activeLoader":true} }}

Upvotes: 1

Views: 769

Answers (2)

Hikmat Sijapati
Hikmat Sijapati

Reputation: 7004

Try as below:Your array is multidimensional.

/*$json = '{"data":{"0":{"ID":"1","Name":"3 Piece Roundabout Candle Holders","Url": 

"http://url","ModsyStatus":"0","weRplayStatus"

:"0", "ModsyPrice" :"39.95", "weRplayPrice":"39.95","activeLoader":true} }}';*/


$json =json_decode($request->getContent(),true); //get your json
$array = json_decode($json,true);
//print_r($array);
    foreach ($array['data'] as $data){
                $id = $data['ID'];
                $modsyPrice = floor($data['ModsyPrice']);
    }
echo $id."<br/>";
echo $modsyPrice;

Upvotes: 0

Bara&#39; ayyash
Bara&#39; ayyash

Reputation: 1925

ID with upper case : $id = $data->ID;

the same with : ModsyPrice

Upvotes: 1

Related Questions