Laravel 5 Pagination with Query Builder

前端 未结 5 1899
情歌与酒
情歌与酒 2021-01-05 10:18

I\'m making a Laravel Pagination based from my query result and be rendered in my view. I\'m following this guide http://laravel.com/docs/5.1/pagination but I get an error:<

5条回答
  •  情话喂你
    2021-01-05 10:33

    public function getDeliveries($date_from, $date_to)
    {
        $query="your_query_here";
        $deliveries = DB::select($query);
    
        $deliveries = collect($deliveries);
        $perPage = 10;
        $currentPage = \Input::get('page') ?: 1;
        $slice_init = ($currentPage == 1) ? 0 : (($currentPage*$perPage)-$perPage);
        $pagedData = $users->slice($slice_init, $perPage)->all();
        $deliveries = new LengthAwarePaginator($pagedData, count($deliveries), $perPage, $currentPage);
        $deliveries ->setPath('set_your_link_page');
        return $deliveries;
     }
    

提交回复
热议问题