function page(Request request)
{
//默认的搜索框为post传值
if (request->isMethod(‘post’)) {
//获取填写的内容
contents=
request->contents;
//得到数据库中的数据
db=Weibo::all();//定义一个数组,用来保存拼接的语句
arr = array();
//拼接原生的sql语句,1为true`
where=1;//判断输入的内容是否存在,用来搜索if(!empty(
contents)) {
//拼接原生的sql查询条件 使用模糊查询
where.="andcontentlike\"
contents. “%\”“;
//拼接多条件查询
arr[′content′]="contentlike\"
contents . “%\”“;
}
//菜单的请求值
isgai=
request->is_gai;
// dd(
isgai);//菜单的值不为空if(
is_gai == 1 || $is_gai == 0) {
// + 拼接 菜单 查询语句
$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]);
}