title: Modify response structure using Eloquent: API Resources
body: <p>I am newbie in Laravel. I am using laravel as a REST End Point, I use Eloquent: API Resources for transforming my data to JSON.</p>
  
  <p>I am using Collection and Resource to parse my data came from my query. So below is the structure of my response:</p>
  
  <pre><code>data:
      0
          id
          name
      1
          id
          name
  </code></pre>
  
  <p>Now I need to have some categorization in the data, hence I require the data structure to be in below format</p>
  
  <pre><code>data:
      24H
          0
              id
              name
          1
              id
              name
      7D
          0
              id
              name
          1
              id
              name
  </code></pre>
  
  <p>I tried couple of ways to accomplish this, the static way I tried for testing was to change the <strong>ResourceCollection</strong>'s toArray method and append the key 24H for the data we get.</p>
  
  <p>But I know that is not correct and generic way.</p>
  
  <p>I would like to know how I can achieve the above response format in generic and extensible manner.</p>
  
  <p>Your help is much appreciated.</p>
  
  <p>Thanks.</p>