如何创建自定义分页链接? [英] How to create custom pagination link?

查看:76
本文介绍了如何创建自定义分页链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我在分页上有此链接:

Right now i have this link on paginate :

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

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

这是我想要的: www.test.com/search?search=&page=2等等

现在我有这个了

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

如何更改此路线以拥有我想要的路线?

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

我发现了这一点:

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.

推荐答案

您可以像这样保留现有查询.您可以在控制器中定义一个功能

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() }}

这篇关于如何创建自定义分页链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆