Laravel Pagination links not including other GET parameters

前端 未结 12 605
遥遥无期
遥遥无期 2020-12-04 08:35

I am using Eloquent together with Laravel 4\'s Pagination class.

Problem: When there are some GET parameters in the URL, eg: http://site.com/u

相关标签:
12条回答
  • 2020-12-04 09:02

    I think you should use this code in Laravel 5. Also this will work not only with parameter page but also with any other parameter(s):

    $users->appends(request()->input())->links();
    

    Personally, I try to avoid using Facades as much as I can. Using global helper functions is less code and much elegant.

    UPDATE:

    Do not use Input Facade as it is deprecated in Laravel v6+

    0 讨论(0)
  • 2020-12-04 09:03

    Use this construction, to keep all input params but page

    {!! $myItems->appends(Request::capture()->except('page'))->render() !!}
    

    Why?

    1) you strip down everything that added to request like that

      $request->request->add(['variable' => 123]);
    

    2) you don't need $request as input parameter for the function

    3) you are excluding "page"

    PS) and it works for Laravel 5.1

    0 讨论(0)
  • 2020-12-04 09:04

    EDIT: Connor's comment with Mehdi's answer are required to make this work. Thanks to both for their clarifications.

    ->appends() can accept an array as a parameter, you could pass Input::except('page'), that should do the trick.

    Example:

    return view('manage/users', [
        'users' => $users->appends(Input::except('page'))
    ]);
    
    0 讨论(0)
  • 2020-12-04 09:04

    Not append() but appends() So, right answer is:

    {!! $records->appends(Input::except('page'))->links() !!}
    
    0 讨论(0)
  • 2020-12-04 09:06

    Pass the page number for pagination as well. Some thing like this

    $currentPg = Input::get('page') ? Input::get('page') : '1';
        $boards = Cache::remember('boards'.$currentPg, 60, function(){ return WhatEverModel::paginate(15); });

    0 讨论(0)
  • 2020-12-04 09:09

    Include This In Your View Page

     $users->appends(Input::except('page'))
    
    0 讨论(0)
提交回复
热议问题