title: Laravel add custom attribute to paginate result
body: <p>I'm trying to add some data into the paginate result.
  This is the code:</p>
  
  <pre><code>// query select and filter
  [...]
  
  $totalAmount = $sales-&gt;sum('amount');
  $result = $sales-&gt;paginate($rowsPerPage);
  return $result;
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>{
      "datatable": {
          "current_page": 1,
          "data": [
              {
                  "sale": 13047689,
                  "customer": "0017850000104",
                  "date": "2015-12-23 23:15:06",
                  "amount": "129.84",
              }
          ],
          "first_page_url": "http://intranet/api/user/sales/datatable?custom=value&amp;page=1",
          "from": 1,
          "last_page": 1,
          "last_page_url": "http://intranet/api/user/sales/datatable?custom=value&amp;page=1",
          "next_page_url": null,
          "path": "http://intranet/api/user/sales/datatable",
          "per_page": "10",
          "prev_page_url": null,
          "to": 1,
          "total": 1
      }
  }
  </code></pre>
  
  <p>I'd like to add the totalAmount into this paginate object. </p>
  
  <p>What I tried:</p>
  
  <pre><code>$result-&gt;appends('totalAmount', $totalAmount);
  </code></pre>
  
  <p>I find this method over internet but seems it does nothing... The result is exactly like the above without this attribute.</p>
  
  <p>Another method I found is put.</p>
  
  <pre><code>$result-&gt;put('totalAmount', $totalAmount);
  </code></pre>
  
  <p>This method really works but not the way I need. This is for add some rows to the result because it adds the attribute inside "data". This breaks my code when I pass this results for datatable.</p>
  
  <pre><code>{
      "datatable": {
          "current_page": 1,
          "data": {
              "0": {
                  "sale": 13047689,
                  "customer": "0017850000104",
                  "date": "2015-12-23 23:15:06",
                  "amount": "129.84",
              },
              "totalAmount": "129.84"
          },
          "first_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "from": 1,
          "last_page": 1,
          "last_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "next_page_url": null,
          "path": "http://intranet/api/user/sales/datatable",
          "per_page": "10",
          "prev_page_url": null,
          "to": 2,
          "total": 1
      }
  }
  </code></pre>
  
  <p>How can I do it???</p>
  
  <p>I'd like this:</p>
  
  <pre><code>{
      "datatable": {
          "current_page": 1,
          "data": [
              {
                  "sale": 13047689,
                  "customer": "0017850000104",
                  "date": "2015-12-23 23:15:06",
                  "amount": "129.84",
              }
          ],
          "first_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "from": 1,
          "last_page": 1,
          "last_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "next_page_url": null,
          "path": "http://intranet/api/user/sales/datatable",
          "per_page": "10",
          "prev_page_url": null,
          "to": 2,
          "total": 1,
          "totalAmount": "129.84"
      }
  }
  </code></pre>
  
  <p>Or the further step would be:</p>
  
  <pre><code>{
      "datatable": {
          "current_page": 1,
          "data": [
              {
                  "sale": 13047689,
                  "customer": "0017850000104",
                  "date": "2015-12-23 23:15:06",
                  "amount": "129.84",
              }
          ],
          "first_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "from": 1,
          "last_page": 1,
          "last_page_url": "http://intranet/api/user/sales/datatable?page=1",
          "next_page_url": null,
          "path": "http://intranet/api/user/sales/datatable",
          "per_page": "10",
          "prev_page_url": null,
          "to": 2,
          "total": 1,
          "totalData": {
              "accumulated1": 235,
              "accumulated2": 799,
              "accumulated3": 1680,
          },
      }
  }
  </code></pre>
  
  <p>Any help? Thanks.</p>