title: Laravel. Query Builder groupBy
body: <p>So I have table named "<strong>orders</strong>" that has receipt_id to link it with the table named "<strong>receipts</strong>"</p>
  
  <p>I want to group the orders that has the same receipt_id, so in my controller, I used this code;</p>
  
  <pre><code>        $orders = DB::table('orders')
          -&gt;where('status', 0)
          -&gt;groupBy('receipt_id')
          -&gt;get();
  
      return $orders;
  </code></pre>
  
  <p>But unfortunately, it only returns the first one. I have a feeling that I shouldn't be using groupBy. </p>
  
  <p>This is what it currently returns;</p>
  
  <pre><code>{
  id: 1,
  item: "12",
  qty: 123,
  price: "1823.00",
  subtotal: "123.00",
  receipt_id: 123,
  status: 0,
  created_at: null,
  updated_at: null
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I only want to query the <strong>receipts</strong> table, here's what my blade looks like right now and commented what I want to accomplish.</p>
  
  <pre><code>@forelse($orders as $order)
          &lt;div class="col-md-4"&gt;
              &lt;div class="panel panel-default"&gt;
                  &lt;div class="panel-heading text-center"&gt;
                      {{$order-&gt;receipt_id}}
                  &lt;/div&gt;
  
                  &lt;div class="panel-body text-center"&gt;
                      &lt;table class="table table-bordered table-responsive"&gt;
                          &lt;thead&gt;
                              &lt;th&gt;Order&lt;/th&gt;
                              &lt;th&gt;Quantity&lt;/th&gt;
                          &lt;/thead&gt;
  
                          &lt;tbody&gt;
  
                              //all orders that has the same receipt_id will be showed here.
                              &lt;tr&gt;
                                  &lt;td&gt;{{$order-&gt;item}}&lt;/td&gt;
                                  &lt;td&gt;{{$order-&gt;qty}}&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
  
                  &lt;div class="panel-footer clearfix"&gt;
                      &lt;button type="submit" class="btn btn-success pull-right" style="margin-right: 10px;"&gt;
                          &lt;i class="fa fa-check-circle" aria-hidden="true"&gt;&lt;/i&gt; Served
                      &lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          @empty
  
          @endforelse
  </code></pre>
  
  <p>EDIT: Database structure for receipts and orders.</p>
  
  <p>receipts;</p>
  
  <pre><code>Schema::create('receipts', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;decimal('total');
              $table-&gt;decimal('vatable');
              $table-&gt;decimal('vat');
              $table-&gt;decimal('vat_exempt');
              $table-&gt;decimal('vat_zero');
              $table-&gt;decimal('amount_due');
              $table-&gt;decimal('cash');
              $table-&gt;decimal('change_due');
              $table-&gt;integer('receipt_id');
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>orders;</p>
  
  <pre><code>Schema::create('orders', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('item');
              $table-&gt;integer('qty');
              $table-&gt;decimal('price');
              $table-&gt;decimal('subtotal');
              $table-&gt;integer('receipt_id');
              $table-&gt;boolean('status');
              $table-&gt;timestamps();
          });
  </code></pre>