title: Laravel Pagination with eloquent Queries
body: <p>I am trying to paginate my template which has a table on it. </p>
  
  <p>This is my function in the controller which has the eloquent queries. </p>
  
  <pre><code>public function orderbydate()
      {
  
          $order =DB::table('sales_flat_order_items as s')
                  -&gt;leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
                  -&gt;select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
                      DB::Raw('sum(s.row_total) as row_total'),
                      DB::Raw('sum(s.discount_amount) as discount_amount'),
                      DB::Raw('sum(s.tax_amount) as tax_amount'),
                      DB::Raw('sum(s.qty_ordered) as qty_ordered'),
                      DB::Raw('sum(w.subtotal) as subtotal'), 
                      DB::Raw('sum(w.total_invoiced) as total_invoiced'), 
                      DB::Raw('sum(w.shipping_amount) as shipping_amount')))
                  -&gt;where('qty_canceled','=','0')
                  -&gt;where('status','!=','canceled')
                  -&gt;get();
  
          $orderbydate = DB::table('sales_flat_order_items as s')
                  -&gt;leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
                  -&gt;select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
                      DB::Raw('sum(s.row_total) as row_total'),
                      DB::Raw('sum(s.discount_amount) as discount_amount'),
                      DB::Raw('sum(s.tax_amount) as tax_amount'),  
                      DB::Raw('sum(s.qty_ordered) as qty_ordered'),
                      DB::Raw('sum(w.subtotal) as subtotal'),
                      DB::Raw('DATE(w.created_at) days'), 
                      DB::Raw('sum(w.total_invoiced) as total_invoiced'),
                      DB::Raw('sum(w.shipping_amount) as shipping_amount')))
                  -&gt;where('qty_canceled','=','0')
                  -&gt;where('status','!=','canceled')
                  -&gt;groupBy('days')
                  -&gt;orderBy('s.created_at')
                  -&gt;get();
  
              return View::make('sales_flat_orders.orderbydate', compact('order','orderbydate'), ['orderbydate'=&gt;Paginate(3)]);
      }
  </code></pre>
  
  <p>I want to use pagination in my template. So i ma doing like this.</p>
  
  <pre><code>    @foreach(array_chunk($orderbydate-&gt;getCollection()-&gt;all(), 3) as $row)
        &lt;div class = "row"&gt;
            @foreach($row as $s)
            &lt;article class = "col-md-4"&gt;
       &lt;tbody&gt;
        &lt;tr class="odd gradeX"&gt;
           &lt;td&gt;{{date("d F, Y",strtotime($s-&gt;days))}}&lt;/td&gt;
           &lt;td&gt;{{ round($s-&gt;qty_ordered, 2) }}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;subtotal,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;tax_amount,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;discount_amount,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;row_total,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;amount_refunded,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;total_invoiced,2)}}&lt;/td&gt;
           &lt;td&gt;{{round($s-&gt;shipping_amount,2)}}&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/article&gt;
       @endforeach
      @endforeach
  </code></pre>
  
  <p>But thins does not work. Where am i going wrong?</p>
  
  <p>Thanks in advance</p>