laravel 的 分頁以及條件搜尋後分頁
阿新 • • 發佈:2018-12-24
//後臺的資料查詢 public function index(Request $request) { $tid = empty($request->input('tid'))?0:$request->input('tid'); $content = empty($request->input('content'))?"":$request->input('content'); if($tid==0) { $where=">"; } else { $where ="="; } $news = DB::table("content") ->join('title', 'title.tid', '=', 'content.tid') ->where("content.tid",$where,$tid) ->where('content','like',"%$content%") ->paginate(5); //新聞的分類 $title = DB::table("title")->get(); $news->tid=$tid; $news->content=$content; //新聞內容 return view("news",['title'=>$title,'news'=>$news]); } //前臺分頁資料渲染
{!!$news->appends(array('tid'=>$news->tid,'content'=>$news->content))->render() !!}