Laravel 分页和排序表

1 php sorting pagination laravel

我正在使用排序功能和分页,但是当我对任何列使用排序时出现问题,但是当我使用分页单击到下一页时,排序会发生变化,并且必须再次单击该列进行排序。那么如何在使用分页时保持排序?

<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>
Run Code Online (Sandbox Code Playgroud)
public function index()
{
    $checks = Checks::orderBy('id', 'asc')->get();

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

    return view('home',compact('checks'));
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*rre 6

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

{{ $users->appends(['sort' => 'votes'])->links() }}
Run Code Online (Sandbox Code Playgroud)

替换sort为您的可排序查询,以及votes类似的内容request()->sort