Laravel 5 Pagination with Query Builder

前端 未结 5 1901
情歌与酒
情歌与酒 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:28

    You set it by using the custom pagination..

    $query = "Your Query here";
    
    $page = 1;
    $perPage = 5;
    $query = DB::select($query);
    $currentPage = Input::get('page', 1) - 1;
    $pagedData = array_slice($query, $currentPage * $perPage, $perPage);
    $query =  new Paginator($pagedData, count($query), $perPage);
    $query->setPath('Your Url');
    
    $this->data['query'] = $query;
    
    return view('Your_view_file', $this->data, compact('query'));
    

    Here you can specify the path by using the setpath().

    In your View

    @foreach($query as $rev)
    //Contents
    @endforeach
    appends($_REQUEST)->render(); ?>
    

    The appends will append the data.

    Thank you.

提交回复
热议问题