How to create custom pagination link?

核能气质少年 提交于 2019-12-25 09:13:25

问题


Right now i have this link on paginate :

www.test.com/search/filter?page=1

www.test.com/search/filter?page=2

and what i want is this: www.test.com/search?search=&page=2 and so on

Right now i have this:

{!! $properties->appends(['toggle' => Request::get('toggle'), 'search' => Request::get('search')])->render() !!}

How can i change this to have route like this what i want?

i found this:

Route::get('users', function () {
    $users = App\User::paginate(15);

    $users->setPath('custom/url');

    //
});

But problem is that i use one function for multiple stuff so i can not set path in controller.


回答1:


You can keep your existing query like this. you can define one function in your controller

public function getExistingQueryParams()
{
    $existingQueryParams = [];

    foreach (request()->all() as $key => $value)
    {
        if ($key != 'page')
        {
            $existingQueryParams[$key] = urldecode($value);
        }
    }

    return $existingQueryParams;
}

In your controller's function which is returning the view call this function.

$existingQuery = $this->getExistingQueryParams();

Pass this variable in your view and in your view you can use it like this

{{ $propertiers->appends($existingQuery)->links() }}


来源:https://stackoverflow.com/questions/41953914/how-to-create-custom-pagination-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!