laravel paginator在where子句中不与LIKE一起使用

时间:2018-10-10 19:37:24

标签: laravel paginator

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 ?)

值应存储在session或flash_session中?但未检索到LIKE值

1 个答案:

答案 0 :(得分:5)

您必须append个自定义值到分页链接:

$articles = $query->paginate(3)->appends($request->only('search_qs'));