0

I have a result from laravel-mongodb query, I don't know how to parse this arrays, enter image description here

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, enter image description here

1 Answer 1

1

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;
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! this helped me with getting my results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.