title: How to manually map collection using laravel/php and get total amount
body: <p>I currently have the below json response that the API is returning. I am able to return it using Laravel Eloquent. There are several users and each user has a several receipts. A receipt has types and status. I want to try to get the total sum amount for each receipt that is related to its type and status. I was able to return the below json response using</p>
  
  <p><code>$this-&gt;user-&gt;with('receipts')-&gt;has('receipts')-&gt;get(['id', 'name']);</code></p>
  
  <p>I have tried using multiple laravel collections methods <a href="https://laravel.com/docs/5.8/collections#available-methods" rel="nofollow noreferrer">https://laravel.com/docs/5.8/collections#available-methods</a> But I am still unable to get the desired response.</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "kent",
      "receipts": [
        {
          "id": 1,
          "user_id": 1,
          "type_id": 1,
          "status": 0,
          "amount": 100
        },
        {
          "id": 2,
          "user_id": 1,
          "type_id": 1,
          "status": 0,
          "amount": 100
        },
        {
          "id": 3,
          "user_id": 1,
          "type_id": 2,
          "status": 1,
          "amount": 50
        },
        {
          "id": 4,
          "user_id": 1,
          "type_id": 2,
          "status": 0,
          "amount": 30
        },
        {
          "id": 5,
          "user_id": 1,
          "type_id": 2,
          "status": 0,
          "amount": 30
        },
        {
          "id": 6,
          "user_id": 1,
          "type_id": 1,
          "status": 0,
          "amount": 20
        },
        {
          "id": 7,
          "user_id": 1,
          "type_id": 1,
          "status": 1,
          "amount": 10
        }
      ]
    },
    {
      "id": 2,
      "name": "allison",
      "receipts": [
        {
          "id": 9,
          "user_id": 2,
          "type_id": 1,
          "status": 0,
          "amount": 20
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I expect to get this:</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "kent",
      "receipts": [
        {
          "performance and deleted": 220,
          "performance and not deleted": 10,
          "project and deleted": 60,
          "project and deleted": 50
        }
      ]
    },
    {
      "id": 2,
      "name": "allison",
      "receipts": [
        {
          "performance and deleted": 20,
          "performance and not deleted": 0,
          "project and deleted": 0,
          "project and not deleted": 0
        }
      ]
    }
  ]
  </code></pre>
  
  <p>My main concern is to use laravel collection methods and easy to read code to get my expected result</p>