Reputation: 141
I have a result from laravel-mongodb query, I don't know how to parse this arrays,
as you can see in this collection , in "taggeduser" I have "-storage" array and i just want to get username's inside storage array in every collections, I wrote this code but it's a mess and not working,
foreach ($tagged as $tags){
$temp = $tags['taggeduser'];
foreach ($temp as $key => $value){
$users[] = $value
}
}
returns all values, and i can't access to 'username' field in foreach,
Upvotes: 0
Views: 644
Reputation: 342
Use mapping more info here
https://laravel.com/docs/7.x/collections#method-map
example
$result = $tagged->map(function ($item, $key) {
return $item['users'] = the username that you need to add here;
});
Upvotes: 1