通过分页保留搜索参数

Keep Search Parameters Through Pagination

Laravel(4.2) 有点新,我的搜索功能分页有问题。到目前为止,我已经能够成功地进行搜索,尽管在极少数情况下它实际上会转到第二页并重置为简单的“?page=2”

下面是表单的代码。

{{ Form::open(array('method' => 'post', 'name' => 'all', 'novalidate' => 'novalidate')) }}
                          <input type="text" name="srch_lname" class="input-large" value="{{ Input::old('srch_lname', Session::get('srch_lname')) }}" />

                          <input type="text" name="srch_fname" class="input-large" value="{{ Input::old('srch_fname', Session::get('srch_fname')) }}" />
.
.
.
<?php echo $employees->links(); ?>

以及处理搜索的控制器。

public function getIndex() {

        $srch_lname = Session::get('srch_lname');
        $srch_fname = Session::get('srch_fname');

        $employees = vEmployees::co()->restrictions()
            ->where('lastname', 'LIKE', $srch_lname . '%')
            ->where('firstname', 'LIKE', $srch_fname . '%')
            ->orderBy('lastname')
            ->orderBy('firstname')
            ->paginate(10);

        return View::make('index')
            ->with('employees', $employees)
            ->with('title', 'Users')
            ->with('pagetitle', 'Employees')
            ->with('pagedescription', '')
    }


    public function postIndex() {

        if (Input::has('btnSearch')) {

            return Redirect::to('/employees')->with('search', 1)
                ->with('srch_lname', Input::get('srch_lname'))
                ->with('srch_fname', Input::get('srch_fname'))

我一直在尝试在整个 SO 中找到的其他一些解决方案,尽管它最终会导致问题或让我回到同样的问题。

任何朝着正确方向的推动都会很棒!

将搜索数据附加到分页中links()

<?php echo $employees->appends(array("srch_lname" => ...))->links(); ?>

http://laravel.com/docs/4.2/pagination#appending-to-pagination-links