title: Laravel 5 using raw query getting result to array
body: <p>I have a query from my database where i want to make the result into array, I am using laravel but i am not using Eloquent because i am just a beginner. Here is my query.</p>
  
  <p>Query: </p>
  
  <pre><code> $array = array();
  
          $shippings = DB::table('shipping_table')
          -&gt;select('*')
          -&gt;leftJoin('shipping_products', function ($join) use ($array) {
              $join-&gt;on('shipping_products.shipping_id','=','shipping_table.shipping_id');
          })
          -&gt;leftJoin('products', function ($join) use ($array) {
              $join-&gt;on('products.product_id', '=', 'shipping_products.product_id');
          })-&gt;get();
  
          dd($shippings);
  </code></pre>
  
  <p>Here my query result is this:</p>
  
  <pre><code>Collection {#296 ▼
    #items: array:2 [▼
      0 =&gt; {#297 ▼
        +"shipping_id": 56
        +"shipping_date": null
        +"total_amount": 95000
        +"shipping_receiver": "Robert"
        +"shipping_address": "test"
        +"mobile_number": "09992238185"
        +"user_id": 1
        +"shipping_status": 0
        +"paywith": "paypal"
        +"id": 9
        +"product_id": 1
        +"quantity": 15
        +"subcategory_id": 1
        +"featured_img": "sample image1.jpg"
        +"product_name": "Product 1"
        +"description": "Product 1 desc"
        +"price": 46000.0
        +"status": "published"
        +"created_at": "2017-10-04 05:29:59"
        +"updated_at": "2017-10-04 05:29:59"
      }
      1 =&gt; {#287 ▼
        +"shipping_id": 56
        +"shipping_date": null
        +"total_amount": 95000
        +"shipping_receiver": "Robert"
        +"shipping_address": "Test"
        +"mobile_number": "09992238185"
        +"user_id": 1
        +"shipping_status": 0
        +"paywith": "paypal"
        +"id": 10
        +"product_id": 2
        +"quantity": 10
        +"subcategory_id": 1
        +"featured_img": "DSC04477-e1490885078524-200x300.jpg"
        +"product_name": "Product 2"
        +"description": "Product 2 desc"
        +"price": 49000.0
        +"status": "published"
        +"created_at": "2017-10-04 05:58:55"
        +"updated_at": "2017-10-04 05:58:55"
      }
    ]
  }
  </code></pre>
  
  <p>In the result that i've got, i am not satisfied because i want a result like this:</p>
  
  <pre><code>Collection {#296 ▼
    #items: array:1 [▼
      0 =&gt; {#297 ▼
        +"shipping_id": 56
        +"shipping_date": null
        +"total_amount": 95000
        +"shipping_receiver": "test"
        +"shipping_address": "tester"
        +"mobile_number": "09992238185"
        +"user_id": 1
        +"shipping_status": 0
        +"paywith": "paypal"
         #products: array:2 {
           0 =&gt; {
            +"product_id": 1
            +"quantity": 15
            +"subcategory_id": 1
            +"featured_img": "sample.jpg"
            +"product_name": "Product 1"
            +"description": "Product desc 1"
            +"price": 46000.0
            +"status": "published"
            +"created_at": "2017-10-04 05:29:59"
            +"updated_at": "2017-10-04 05:29:59" 
          }
          1 =&gt; {
            +"product_id": 2
            +"quantity": 10
            +"subcategory_id": 1
            +"featured_img": "DSC04477-e1490885078524-200x300.jpg"
            +"product_name": "Product 2"
            +"description": "Product Desc 2"
            +"price": 46000.0
            +"status": "published"
            +"created_at": "2017-10-04 05:29:59"
            +"updated_at": "2017-10-04 05:29:59" 
          }
      }
  </code></pre>
  
  <p>how can i make it to this? please help me build with the correct query. I want to make the products as sub array</p>
  
  <p>Here is my table structure:</p>
  
  <p>Shipping table:</p>
  
  <pre><code>Ship_ID (INT AUTO INC)
  AMOUNT (DOUBLE,2)
  NAME (VARCHAR)
  SHIP_DATE (DATE)
  RECEIVER (VARCHAR)
  </code></pre>
  
  <p>Shipping_products:</p>
  
  <pre><code>ID (INT AUTO INC)
  Ship_id (foreign key from shipping table)
  Product_id
  </code></pre>
  
  <p>Products_table:</p>
  
  <pre><code>Product_id (Auto Inc)
  name(varchar)
  Qty(int)
  Description (varchar)
  </code></pre>