laravel - laravel 分页器在 where 子句中不使用 LIKE
问题描述
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 值
解决方案
您必须将这样的自定义值附加到分页链接:
$articles = $query->paginate(3)->appends($request->only('search_qs'));
推荐阅读
- java - 重新加载 RecyclerView 不会更新项目
- delphi - Delphi Firemonkey 获取 UTC 时间
- javascript - 使用 Js 更改特定样式的属性
- python - Sklearn SVM 在明显线性可分离的数据集上生成错误的边界线
- r - 在 R 中读取 XML 文件并在节点具有不同长度和内容时创建数据框
- python - 如何在 Python 中更改直方图 Y 轴上的值
- jmeter - 无法将值从 beanshell 预处理器传递给采样器?
- javascript - PostgreSQL 与 TypeORM 错误“在 \"Sep\" 处或附近出现语法错误”
- powerbi - 过滤器以意想不到的方式影响测量
- php - 如何在 php 中的子项数组中搜索?