关于搜索功能的实现原理(laravel框架)

这里的搜索功能主要基于表单get提交实现的

选择分类: 全部 @foreach($category as $c) {{$c->class_name}} @endforeach 文章标题:
php部分逻辑

public function article_list(){
//echo ‘zoule’;exit; 测试表单是否走进方法中 大家随意写
s h o w n u m = 1 ; i f ( a r r a y k e y e x i s t s ( ′ c l a s s ′ , shownum = 1; if(array_key_exists('class', shownum=1;if(arraykeyexists(class,_GET)||array_key_exists(‘keywords’,KaTeX parse error: Expected '}', got 'EOF' at end of input: …1'; if(_GET[‘class’]){
//Article模型 leftJoin表连接 查询根据俩个表里的这些字段来执行
p o s t d a t a = A r t i c l e : : l e f t J o i n ( ′ c a t e g o r y ′ , f u n c t i o n ( postdata = Article::leftJoin('category', function( postdata=Article::leftJoin(category,function(join) {
KaTeX parse error: Expected 'EOF', got '}' at position 60: …id'); }̲)->select(['art…_GET[‘class’])->orderBy(‘release_time’,‘desc’)->paginate(KaTeX parse error: Expected 'EOF', got '}' at position 17: …hownum); }̲elseif(_GET[‘keywords’]){
p o s t d a t a = A r t i c l e : : l e f t J o i n ( ′ c a t e g o r y ′ , f u n c t i o n ( postdata = Article::leftJoin('category', function( postdata=Article::leftJoin(category,function(join) {
KaTeX parse error: Expected 'EOF', got '}' at position 60: …id'); }̲)->select(['art…_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’;
p o s t d a t a = A r t i c l e : : l e f t J o i n ( ′ c a t e g o r y ′ , f u n c t i o n ( postdata = Article::leftJoin('category', function( postdata=Article::leftJoin(category,function(join) {
KaTeX parse error: Expected 'EOF', got '}' at position 57: …ry.id'); }̲)->select(['art…shownum);
}
//分类id不是父id
c a t e g o r y = D B : : t a b l e ( ′ c a t e g o r y ′ ) − > w h e r e ( ′ p a r e n t i d ′ , ′ ! = ′ , ′ 0 ′ ) − > g e t ( ) ; / / 渲 染 页 面 传 递 参 数 r e t u r n v i e w ( ′ b a c k e n d . a r t i c l e l i s t ′ , [ ′ p o s t d a t a ′ = > category = DB::table('category')->where('parent_id','!=','0')->get(); //渲染页面 传递 参数 return view('backend.article_list',['postdata'=> category=DB::table(category)>where(parentid,!=,0)>get();//returnview(backend.articlelist,[postdata=>postdata,‘shownum’=> s h o w n u m , ′ c a t e g o r y ′ = > shownum,'category'=> shownum,category=>category]);
}
http://mam.yisuping.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值