【发布时间】:2018-10-10 19:37:23
【问题描述】:
laravel 分页器不能在 where 子句中使用 LIKE
laravel/框架版本: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 值
【问题讨论】:
-
实际的搜索词来自哪里?是网址参数吗?
-
yes from url parameter, sent from a search input texbox,
-
静态文本不会出现同样的问题,几个小时我都头疼,tks!!!