Reputation: 39
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
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