laravel简单的搜索分页

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]);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值