Laravel框架搜索分页功能示例

所属分类: 网络编程 / PHP编程 阅读数: 1472
收藏 0 赞 0 分享

本文实例讲述了Laravel框架搜索分页功能。分享给大家供大家参考,具体如下:

控制器controller

/**
 * 文章搜索
 *
 * @author YING
 * @param void
 * @return void
 */
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

/**
 * 文章搜索
 *
 * @author YING
 * @param void
 * @return void
 */
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

<div class="list-page" style="margin-left: 400px">
{{$artInfo->appends(['cate_id' => $cate_id])->appends(['title' => $title])->render()}}
</div>

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

更多精彩内容其他人还在看

解决laravel中日志权限莫名变成了root的问题

今天小编就为大家分享一篇解决laravel中日志权限莫名变成了root的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Laravel框架中集成MongoDB和使用详解

今天小编就为大家分享一篇Laravel框架中集成MongoDB和使用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

浅谈laravel框架sql中groupBy之后排序的问题

今天小编就为大家分享一篇浅谈laravel框架sql中groupBy之后排序的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

mac pecl 安装php7.1扩展教程

今天小编就为大家分享一篇mac pecl 安装php7.1扩展教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Mac下关于PHP环境和扩展的安装详解

今天小编就为大家分享一篇Mac下关于PHP环境和扩展的安装详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

laravel 解决groupBy时出现的错误 isn't in Group By问题

今天小编就为大家分享一篇laravel 解决groupBy时出现的错误 isn't in Group By问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Laravel 框架返回状态拦截代码

今天小编就为大家分享一篇Laravel 框架返回状态拦截代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

在laravel框架中实现封装公共方法全局调用

今天小编就为大家分享一篇在laravel框架中实现封装公共方法全局调用,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

在Laravel 的 Blade 模版中实现定义变量

今天小编就为大家分享一篇在Laravel 的 Blade 模版中实现定义变量,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Laravel基础_关于view共享数据的示例讲解

今天小编就为大家分享一篇Laravel基础_关于view共享数据的示例讲解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享
查看更多