title: Group By Query Builder not returning Object in Laravel
body: <p>I am having issue with a groupby function. Please i need help.
  Here is my code</p>
  
  <pre><code>$rate = Rate::orderBy('created_at', 'desc')-&gt;get()-&gt;groupBy([function($item) {
                  return $item-&gt;location;
              },
              function($item) {
                  return ['currency' =&gt; $item-&gt;currency];
              },
              function($item) {
                  return ['time' =&gt; $this-&gt;rateTime($item-&gt;created_at-&gt;format('H'))];
              }]
          );
  </code></pre>
  
  <p>This is the result its returning</p>
  
  <pre><code>"data": {
          "Lagos": {
              "GBP": {
                  "Afternoon": [
                      {
                          "id": 6,
                          "currency": "GBP",
                          "buy_rate": "350",
                          "sell_rate": "450",
                          "location": "Lagos",
                          "created_at": "2020-05-25 16:00:41",
                          "updated_at": "2020-05-25 16:00:41"
                      }
                  ]
              },
              "USD": {
                  "Morning": [
                      {
                          "id": 5,
                          "currency": "USD",
                          "buy_rate": "390",
                          "sell_rate": "450",
                          "location": "Lagos",
                          "created_at": "2020-05-25 04:04:00",
                          "updated_at": "2020-05-25 04:04:00"
                      }
                  ]
              },
              "EUR": {
                  "Evening": [
                      {
                          "id": 4,
                          "currency": "EUR",
                          "buy_rate": "530",
                          "sell_rate": "545",
                          "location": "Lagos",
                          "created_at": "2020-05-21 18:33:30",
                          "updated_at": "2020-05-21 18:33:30"
                      }
                  ]
              },
              "NGN": {
                  "Afternoon": [
                      {
                          "id": 3,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Lagos",
                          "created_at": "2020-05-21 16:41:19",
                          "updated_at": "2020-05-21 16:41:19"
                      },
                      {
                          "id": 2,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Lagos",
                          "created_at": "2020-05-21 16:39:15",
                          "updated_at": "2020-05-21 16:39:15"
                      }
                  ]
              }
          },
          "Ghana": {
              "NGN": {
                  "Afternoon": [
                      {
                          "id": 1,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Ghana",
                          "created_at": "2020-05-21 16:38:26",
                          "updated_at": "2020-05-21 16:38:26"
                      }
                  ]
              }
          }
      }
  }
  </code></pre>
  
  <p>But this is what i need</p>
  
  <pre><code>"data": {
          "Location": "Lagos",
                         {
             "Currency": "GBP" {
                  "Afternoon": [
                      {
                          "id": 6,
                          "currency": "GBP",
                          "buy_rate": "350",
                          "sell_rate": "450",
                          "location": "Lagos",
                          "created_at": "2020-05-25 16:00:41",
                          "updated_at": "2020-05-25 16:00:41"
                      }
                  ]
              },
              "Currency": "USD",
                    {
                  "Morning": [
                      {
                          "id": 5,
                          "currency": "USD",
                          "buy_rate": "390",
                          "sell_rate": "450",
                          "location": "Lagos",
                          "created_at": "2020-05-25 04:04:00",
                          "updated_at": "2020-05-25 04:04:00"
                      }
                  ]
              },
              "Currency": "EUR" {
                  "Evening": [
                      {
                          "id": 4,
                          "currency": "EUR",
                          "buy_rate": "530",
                          "sell_rate": "545",
                          "location": "Lagos",
                          "created_at": "2020-05-21 18:33:30",
                          "updated_at": "2020-05-21 18:33:30"
                      }
                  ]
              },
              "Currency": "NGN" {
                  "Afternoon": [
                      {
                          "id": 3,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Lagos",
                          "created_at": "2020-05-21 16:41:19",
                          "updated_at": "2020-05-21 16:41:19"
                      },
                      {
                          "id": 2,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Lagos",
                          "created_at": "2020-05-21 16:39:15",
                          "updated_at": "2020-05-21 16:39:15"
                      }
                  ]
              }
          },
          "Location": "Ghana" {
             "Currency": "NGN" {
                  "Afternoon": [
                      {
                          "id": 1,
                          "currency": "NGN",
                          "buy_rate": "20.45",
                          "sell_rate": "32.34",
                          "location": "Ghana",
                          "created_at": "2020-05-21 16:38:26",
                          "updated_at": "2020-05-21 16:38:26"
                      }
                  ]
              }
          }
      }
  }
  </code></pre>
  
  <p>I want to be get an object with keys and values and not only the values. Been trying diferent ways but still now getting it. I will be glad if someone could be of help to me.</p>