title: Laravel 5.5 API Resource Collection using array
body: <p>I am using laravel 5.5 API resource collection for showing list of products. I am using an array instead of the modal object. I got my list of items but i am not sure how to show item variant array in the response. The actual response array passing to the api resource are:</p>
  
  <pre><code>{
  "ID": 3160,
  "UserID": 3302,
  "ItemName": "2",
  "Description": "2",
  "Price": 2,
  "StockLimited": true,
  "StockQuantity": 19,
  "CurrencyCode": "USD",
  "ImageUrl": "/images/items/Item3302-636434761494584365-qq5HFm.png",
  "VariantItems": [
    {
      "ID": 3181,
      "ItemName": "2",
      "Price": 0,
      "StockLimited": false,
      "StockQuantity": 0,
      "CurrencyCode": "USD",
      "Variants": [
        {
          "Id": 1099,
          "Name": "Red",
          "VariantGroupId": 1027,
          "VariantGroupName": "Colour"
        },
        {
          "Id": 1111,
          "Name": "S",
          "VariantGroupId": 1028,
          "VariantGroupName": "Size"
        }
      ]
    },
    {
      "ID": 3182,
      "ItemName": "2",
      "Price": 0,
      "StockLimited": false,
      "StockQuantity": 0,
      "CurrencyCode": "USD",
      "Variants": [
        {
          "Id": 1099,
          "Name": "Red",
          "VariantGroupId": 1027,
          "VariantGroupName": "Colour"
        },
        {
          "Id": 1112,
          "Name": "M",
          "VariantGroupId": 1028,
          "VariantGroupName": "Size"
        }
      ]
    }
  
  ],
  "MerchantName": "seller",
  "VariantGroupLists": [
    {
      "VariantGroupName": "Colour",
      "Names": [
        "Red",
        "Grey",
        "Navy"
      ]
    },
    {
      "VariantGroupName": "Size",
      "Names": [
        "S",
        "M",
        "L",
        "XL"
      ]
    }
  ]  
  }
  </code></pre>
  
  <p>My ItemResourceCollection</p>
  
  <pre><code>public function toArray($request)
  {
  
  
      return [
          'data' =&gt; $this-&gt;collection-&gt;map(function ($item) use ($request) {
              return (new ItemResource($item))-&gt;toArray($request);
          })
      ];
  }
  </code></pre>
  
  <p>My ItemResource</p>
  
  <pre><code> public function toArray($request)
  {
  
      return [
          "item_id" =&gt; $this-&gt;resource-&gt;ID,
          "item_name" =&gt; $this-&gt;resource-&gt;ItemName,
          "description" =&gt;$this-&gt;resource-&gt;Description,
          "item_price"=&gt;$this-&gt;resource-&gt;Price,
          "stock_qty"=&gt;$this-&gt;resource-&gt;StockQuantity,
          "currency_code"=&gt;$this-&gt;resource-&gt;CurrencyCode,
          "item_image_url"=&gt;$this-&gt;resource-&gt;ImageUrl,
  
      ];
  
  }
  
  public function with($request)
  {
  
      return ['item_varients' =&gt; [new ItemResource($this-&gt;resource-&gt;VariantItems)]]; 
  }
  </code></pre>
  
  <p>What I am trying to achieve is this result:</p>
  
  <pre><code>[
  
  {
      "item_id": 3160,
      "item_name": "BLACK COWL NECK DRESS WITH DIAMANTE DETAIL",
      "description": "Test test",
      "item_price": 16.99,
      "stock_qty": 20,
      "currency_code": "SGD",
      "item_image_url": "/images/items/Item18-636231488325192562-GoiIBl.png",
      "item_varients": [
        {
          "id": 29,
          "name": "Red",
          "varientgroupId": 11,
          "varientgroupname": "Color"
        }
      ]
    }
  ]
  </code></pre>
  
  <p>the <code>with()</code> method in ItemResource is not working. How do I add the <code>"item_varients"</code> array in the resource response?</p>