susmita rai
susmita rai

Reputation: 39

How can I access specific object properties in laravel?

I tried using data_get() function, But it doesn't return me anything.

Can any one help me to access data array from the below object in laravel??

Any information regarding this would be appreciated. Thank You!!

$data = data_get($object,'data');

 $object = {
  "success": true,
  "message": "Something....",
  "data": [
   
       {
          "id": 9,
          "name": "name1"
       },
       {
          "id": 10,
          "name": "name2"
       }

   ]
}

Upvotes: 1

Views: 1819

Answers (2)

Bbxxest Olumese
Bbxxest Olumese

Reputation: 11

$data = json_decode($object, true); $data->message;

Upvotes: 1

Digvijay
Digvijay

Reputation: 8927

You can convert the json object into an array using json_decode().

$newObject = json_decode($object, true);

From here, you can simply access it like

$data = $newObject['data'];

$message = $newObject['message'];

Upvotes: 3

Related Questions