使用Laravel框架怎么实现一个搜索分页功能-创新互联
本篇文章给大家分享的是有关使用Laravel框架怎么实现一个搜索分页功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

控制器controller
public function mesArticleSearch()
{
//接值
$input=Input::get();
//调用模型查询
//实例化类
$cate=new Article();
//调用自定义方法 查询分类
$artInfo=$cate->searchAll($input);
//从session的用户名
$username=session('user_name');
//实例化类
$cate=new Category();
//调用自定义方法 查询分类
$cateInfo=$cate->selectAll();
return view('admin.article',['username'=>$username,'artInfo'=>$artInfo,'cateInfo'=>$cateInfo,'cate_id'=>$input['cate_id'],'title'=>$input['title']]);
}模型model
public function searchAll($input)
{
//判断
if($input['cate_id']!=0&&$input['title']!=""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where(array('category.cate_id'=>$input['cate_id']))
->where('title','like','%'.$input['title'].'%')
->orderBy('article.sort','DESC')
->paginate(3);
}else if($input['cate_id']!=0&&$input['title']==""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where(array('category.cate_id'=>$input['cate_id']))
->orderBy('article.sort','DESC')
->paginate(3);
}else if ($input['cate_id']==0&&$input['title']!=""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where('title','like','%'.$input['title'].'%')
->orderBy('article.sort','DESC')
->paginate(3);
}else{
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->orderBy('article.sort','DESC')
->paginate(3);
}
}比较low
视图view
{{$artInfo->appends(['cate_id' => $cate_id])->appends(['title' => $title])->render()}}
以上就是使用Laravel框架怎么实现一个搜索分页功能,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
文章标题:使用Laravel框架怎么实现一个搜索分页功能-创新互联
当前链接:http://www.jxjierui.cn/article/dipihs.html


咨询
建站咨询
