How to automatically append query string to laravel pagination links?

后端 未结 9 1971
失恋的感觉
失恋的感觉 2020-12-01 06:06

I am working on search filter on checkbox click, with Laravel and Ajax call. So I get results when I click on a checkbox. my query is as follows:

    $editor         


        
相关标签:
9条回答
  • 2020-12-01 06:52

    For the latest version of Laravel at the moment (5.2), you can just use the Request facade to retrieve the query string and pass that to your paginator's appends() method

    $input = Request::input();
    $myModelsPaginator = App\Models\MyModel::paginate();
    $myModelsPaginator->appends($input);
    
    0 讨论(0)
  • 2020-12-01 07:01

    Check the answer from @Arda, as it's global solution. Below you can find how to do it manually.

    Use appends on Paginator:

    $querystringArray = Input::only(['search','filter','order']); // sensible examples
    
    // or:
    $querystringArray = ['queryVar' => 'something', 'anotherVar' => 'something_else'];
    
    $temp->appends($querystringArray);
    
    0 讨论(0)
  • 2020-12-01 07:06

    you can used request helper in view as same

    {{ $users->appends(request()->query())->links() }}
    
    0 讨论(0)
  • 2020-12-01 07:07

    Append all input except the actual page, form token and what you don't want to pass:

    $paginatedCollection->appends(request()->except(['page','_token']));
    
    0 讨论(0)
  • 2020-12-01 07:07

    As of Laravel 7, you can call the withQueryString() method on your Paginator instance.

    Quote from the documentation:

    If you wish to append all current query string values to the pagination links you may use the withQueryString method:

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

    See "Appending To Pagination Links": https://laravel.com/docs/7.x/pagination#displaying-pagination-results

    0 讨论(0)
  • 2020-12-01 07:08
    {{ $users->appends($_GET)->links() }}
    

    It will append all query string parameters into pagination link

    0 讨论(0)
提交回复
热议问题