laravel简单的搜索分页
function page(Request request)
{
//默认的搜索框为post传值
if (request->isMethod(‘post’)) {
//获取填写的内容
//得到数据库中的数据
//拼接原生的sql语句,1为true`
//拼接原生的sql查询条件 使用模糊查询
//拼接多条件查询
}
//菜单的请求值
// dd(
// + 拼接 菜单 查询语句
$where .= " and is_show =" . $is_gai;
//拼接 菜单 查询条件
$arr ["is_show"] = $is_gai;
}
$db = Weibo::whereRaw($where)->join("user_infos", "user_infos.user_id", "=", "weibos.user_id")
->select("weibos.*", "user_infos.nickname");
$weibos = $db->paginate(2);
//appends把条件追加到URL里面
$weibos = $weibos->appends($arr);
return view("admin/weibo", ["weibos" => $weibos]);
}
/***get的传递方式用来分页查询点击下一页***/
$arr = array();
$where = 1;
//get的接收方式
if (!empty($_GET["content"])) {
$where .= " and " . $_GET["content"];
$arr ["content"] = $_GET["content"];
}
$is_gai = $request->is_gai;
$show = $_GET["is_show"];
if ($show == 1 || $show == 0) {
$where .= " and is_show =" . $show;
$arr ["is_show"] = $show;
}
//原生sql拼接语句
$db = Weibo::whereRaw($where)->join("user_infos", "user_infos.user_id", "=", "weibos.user_id")
->select("weibos.*", "user_infos.nickname");
//分页
$weibos = $db->paginate(2);
//appends把条件追加到URL里面
$weibos = $weibos->appends($arr);
return view("admin/weibo", ["weibos" => $weibos]);
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: 数组操作系列之两个数组拼接,改变id从0开始
- 下一篇: PHP 三级分类