Question: i need to pass My custom data to the same level of array of resource but it goes out of array

```
return CategoryProductsResource::collection(Category::whereNull('parent_id')->get())
  ->additional([
                'data' => [
                    'id' => 9999,
                    'name' => 'How Offers',
                    'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
                    'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
                ]
            ]);

```

[json output](https://i.stack.imgur.com/2jNAG.png)

[![enter image description here](https://i.stack.imgur.com/2jNAG.png)](https://i.stack.imgur.com/2jNAG.png)

Answer: 
Because additional is for top-level data, use `concat` instaed.

```php
return CategoryProductsResource::collection(Category::whereNull('parent_id')->get())
  ->concat([
                'data' => [
                    'id' => 9999,
                    'name' => 'How Offers',
                    'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
                    'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
                ]
            ]);

```
You may use PHP `array_merge()` function 

```
$categories = Category::whereNull('parent_id')->get()->toArray();

$merged = array_merge($categories, [
           [
             'id' => 9999,
             'name' => 'How Offers',
             'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
             'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
           ]
]);

return CategoryProductsResource::collection(collect($merged));

```