Laravel Pagination links not including other GET parameters

前端 未结 12 604
遥遥无期
遥遥无期 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 08:45

    Laravel 7.x has added new method to paginator:

    ->withQueryString()
    

    So you can use it like:

    {{ $users->withQueryString()->links() }}
    

    For laravel below 7.x use:

    {{ $users->appends(request()->query())->links() }}
    
    0 讨论(0)
  • 2020-12-04 08:48

    You could use

    ->appends(request()->query())
    

    Example in the Controller:

    $users = User::search()->order()->with('type:id,name')
        ->paginate(30)
        ->appends(request()->query());
    
    return view('users.index', compact('users'));
    

    Example in the View:

    {{ $users->appends(request()->query())->links() }}
    
    0 讨论(0)
  • 2020-12-04 08:48

    LARAVEL 5

    The view must contain something like:

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

    0 讨论(0)
  • 2020-12-04 08:50

    for who one in laravel 5 or greater in blade:

    {{ $table->appends(['id' => $something ])->links() }}
    

    you can get the passed item with

    $passed_item=$request->id;
    

    test it with

    dd($passed_item);
    

    you must get $something value

    0 讨论(0)
  • 2020-12-04 08:54

    Be aware of the Input::all() , it will Include the previous ?page= values again and again in each page you open !
    for example if you are in ?page=1 and you open the next page, it will open ?page=1&page=2
    So the last value page takes will be the page you see ! not the page you want to see

    Solution : use Input::except(array('page'))

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

    In Laravel 7.x you can use it like this:

    {{ $results->withQueryString()->links() }}
    
    0 讨论(0)
提交回复
热议问题