Laravel框架搜索分頁功能示例
本文實(shí)例講述了Laravel框架搜索分頁功能。分享給大家供大家參考,具體如下:
控制器controller
/** * 文章搜索 * * @author YING * @param void * @return void */ public function mesArticleSearch() { //接值 $input=Input::get(); //調(diào)用模型查詢 //實(shí)例化類 $cate=new Article(); //調(diào)用自定義方法 查詢分類 $artInfo=$cate->searchAll($input); //從session的用戶名 $username=session('user_name'); //實(shí)例化類 $cate=new Category(); //調(diào)用自定義方法 查詢分類 $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>
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。
- Laravel5.5 手動分頁和自定義分頁樣式的簡單實(shí)現(xiàn)
- PHP框架Laravel插件Pagination實(shí)現(xiàn)自定義分頁
- Laravel手動分頁實(shí)現(xiàn)方法詳解
- Laravel+jQuery實(shí)現(xiàn)AJAX分頁效果
- Laravel框架執(zhí)行原生SQL語句及使用paginate分頁的方法
- laravel實(shí)現(xiàn)分頁樣式替換示例代碼(增加首、尾頁)
- laravel自定義分頁效果
- laravel自定義分頁的實(shí)現(xiàn)案例offset()和limit()
- Laravel實(shí)現(xiàn)搜索的時候分頁并攜帶參數(shù)
- 在Laravel中實(shí)現(xiàn)使用AJAX動態(tài)刷新部分頁面
- Laravel實(shí)現(xiàn)ORM帶條件搜索分頁
- Laravel5.1 框架分頁展示實(shí)現(xiàn)方法實(shí)例分析
相關(guān)文章
使用PHP和JavaScript判斷請求是否來自微信內(nèi)瀏覽器
這篇文章主要介紹了使用PHP和JavaScript判斷請求是否來自微信內(nèi)瀏覽器,包括在手機(jī)端的程序上使用微信的分享JS腳本的方法,需要的朋友可以參考下2015-08-08php+jQuery+Ajax簡單實(shí)現(xiàn)頁面異步刷新
這篇文章主要為大家詳細(xì)介紹了php+jQuery+Ajax簡單實(shí)現(xiàn)頁面異步刷新,,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08一個php Mysql類 可以參考學(xué)習(xí)熟悉下
慢慢研究吧,非常適合學(xué)習(xí)的php數(shù)據(jù)庫(mysql)類,也可以拿來直接就用,稍微熟悉一下就可以啦!2009-06-06php二維數(shù)組用鍵名分組相加實(shí)例函數(shù)
php二維數(shù)組以鍵名進(jìn)行分組相加的實(shí)例程序2013-11-11php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
這篇文章主要介紹了如何在php與js中分別獲取客戶度mac地址的方法,需要的朋友可以參考下2013-07-07