laravel 如何在分页查询中添加自定义参数

zrfyljdw  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(147)

我想在分页链接中添加自定义搜索参数。
但它重定向到https://localhost:8000/customers?页面=2

$users = User::orderBy('id', 'DESC')
                ->where($column, $operator, $num)
                ->where('email', 'LIKE', "%$key%")
                ->whereBetween('created_at', [$from, $to])
                ->paginate(10);

我需要这是http://localhost:8000/customers?key=ang&role=&from=&to=&page=2

ruarlubt

ruarlubt1#

您可以使用appends方法在URL中附加自定义参数,

$users = User::orderBy('id', 'DESC')
            ->where($column, $operator, $num)
            ->where('email', 'LIKE', "%$key%")
            ->whereBetween('created_at', [$from, $to])
            ->paginate(10)

$users->appends(['key' => 'ang']);

看起来就像

http://localhost:8000/customers?page=2&key=ang

相关问题