laravel 分页器无法在 where 子句中使用 LIKE
laravel paginator is not working with LIKE in where clause
laravel 分页器无法在 where 子句中使用 LIKE
laravel/framework版本:v5.6.33
控制器
$search_qs = $request->input('search');
$query = Article::where("status", 2);
$query->where('title', 'LIKE', '%' . $search_qs . '%');
$articles = $query->paginate(3);
查看
{{ $articles->links() }}
数据库查询
select * from `articles` where `status` = '2' and `title` LIKE '%txt2search%' limit 3 offset 0
!!!好的!!!
但是,当我在分页器中点击第 2 页时
select * from `articles` where `status` = '2' and `title` LIKE '%%' limit 3 offset 3
绑定
0. 2 (`status` = ?)
1. %% (`title` LIKE ?)
值应该存储在会话中,或者 flash_session ??但没有检索到 LIKE 值
您必须 append 像这样的自定义值到分页链接:
$articles = $query->paginate(3)->appends($request->only('search_qs'));
laravel 分页器无法在 where 子句中使用 LIKE
laravel/framework版本:v5.6.33
控制器
$search_qs = $request->input('search');
$query = Article::where("status", 2);
$query->where('title', 'LIKE', '%' . $search_qs . '%');
$articles = $query->paginate(3);
查看
{{ $articles->links() }}
数据库查询
select * from `articles` where `status` = '2' and `title` LIKE '%txt2search%' limit 3 offset 0
!!!好的!!!
但是,当我在分页器中点击第 2 页时
select * from `articles` where `status` = '2' and `title` LIKE '%%' limit 3 offset 3
绑定
0. 2 (`status` = ?)
1. %% (`title` LIKE ?)
值应该存储在会话中,或者 flash_session ??但没有检索到 LIKE 值
您必须 append 像这样的自定义值到分页链接:
$articles = $query->paginate(3)->appends($request->only('search_qs'));