您好,登錄后才能下訂單哦!
這里的搜索功能主要基于表單get提交實(shí)現(xiàn)的
<form action="/backend/auditList" method="get"> <table class="search_tab"> <tr> <th width="120">選擇分類:</th> <td> <select name="class" > <option value="">全部</option> @foreach($category as $c) <option value="{{$c->id}}">{{$c->class_name}}</option> @endforeach </select> </td> <th width="70">文章標(biāo)題:</th> <!--查詢關(guān)鍵詞--> <td><input type="text" name="keywords" placeholder="文章標(biāo)題"></td> <td><input type="submit" name="sub" value="查詢"></td> </tr> </table> </form>
php部分邏輯
public function article_list(){ //echo 'zoule';exit; 測試表單是否走進(jìn)方法中 大家隨意寫 $shownum = 1; if(array_key_exists('class',$_GET)||array_key_exists('keywords',$_GET)){ //echo '111'; if($_GET['class']){ //Article模型 leftJoin表連接 查詢根據(jù)倆個(gè)表里的這些字段來執(zhí)行 $postdata = Article::leftJoin('category', function($join) { $join->on('article.class_id', '=', 'category.id'); })->select(['article.id','category.class_name','article.status','article.title_editing','article.update_time'])->where('article.class_id','=',$_GET['class'])->orderBy('release_time','desc')->paginate($shownum); }elseif($_GET['keywords']){ $postdata = Article::leftJoin('category', function($join) { $join->on('article.class_id', '=', 'category.id'); })->select(['article.id','category.class_name','article.status','article.title_editing','article.update_time'])->where('article.title_editing','=',$_GET['keywords'])->orderBy('release_time','desc')->paginate($shownum); }else{ $postdata = Article::leftJoin('category', function($join) { $join->on('article.class_id', '=', 'category.id'); })->select(['article.id','category.class_name','article.status','article.title_editing','article.update_time'])->orderBy('release_time','desc')->paginate($shownum); } }else{ //echo '2222'; $postdata = Article::leftJoin('category', function($join) { $join->on('article.class_id', '=', 'category.id'); })->select(['article.id','category.class_name','article.status','article.title_editing','article.update_time'])->orderBy('release_time','desc')->paginate($shownum); } //分類id不是父id $category = DB::table('category')->where('parent_id','!=','0')->get(); //渲染頁面 傳遞 參數(shù) return view('backend.article_list',['postdata'=>$postdata,'shownum'=>$shownum,'category'=>$category]); }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。