laravel简单的搜索分页

来源:互联网 发布:数据库视频 编辑:程序博客网 时间:2024/06/11 11:01

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]);    }
原创粉丝点击