I'm using Laravel 5.3 and I have one collection formatted like this:

```
$categories = [
   {
      "id":1,
      "sub_categories":[
         {
            "id":1,
            "category_id":1
         }
      ]
   },
   {
      "id":7,
      "sub_categories":[
         {
            "id":5,
            "category_id":7,
         },
         {
            "id":6,
            "category_id":7
         }
      ]
   }
]

```

I need to extract all sub\_categories arrays but I can't find a way to access the data inside that property. Based on `$categories` collection, I'm expecting to create a new one with this format:

```
[  
   {  
      "id":1,
      "category_id":1
   },
   {  
      "id":5,
      "category_id":7
   },
   {  
      "id":6,
      "category_id":7
   }
]

```

I've tried applying **map** and **pluck** to `$categories` but it retrieves an array filled with *null*.