laravel分页和排序表

问题描述 投票:0回答:1

我正在使用排序功能和分页但是当我对任何列使用sort时的问题工作正常,但是当我使用分页点击下一页时排序更改并且必须再次单击该列进行排序。那么如何在使用分页时保持排序?

<tr>
    <th>
        <div class="checkbox checkbox-replace">
            <input type="checkbox" id="chk-3">

        </div>
    </th>

    <th>@sortablelink('details','Details')</th>
    <th>@sortablelink('postingdate','Date')</th>
    <th>@sortablelink('description','Description')</th>
    <th>@sortablelink('amount','Amount')</th>
    <th>@sortablelink('type','Type')</th>
    <th>@sortablelink('slip','Slip#')</th>
    <th>@sortablelink('vendor_id','Vendor')</th>
    <th>@sortablelink('category_id','Category')</th>
</tr>
public function index()
{
    $checks = Checks::orderBy('id', 'asc')->get();

    $checks= Checks::sortable()->paginate(5);

    return view('home',compact('checks'));
}
php laravel sorting pagination
1个回答
3
投票

您可以通过执行以下操作将查询字符串附加到链接:

{{ $users->appends(['sort' => 'votes'])->links() }}

用你的可排序查询替换sort,用votes之类的东西替换request()->sort

© www.soinside.com 2019 - 2024. All rights reserved.