pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='y3n8r'></tfoot>
  • <i id='y3n8r'><tr id='y3n8r'><dt id='y3n8r'><q id='y3n8r'><span id='y3n8r'><b id='y3n8r'><form id='y3n8r'><ins id='y3n8r'></ins><ul id='y3n8r'></ul><sub id='y3n8r'></sub></form><legend id='y3n8r'></legend><bdo id='y3n8r'><pre id='y3n8r'><center id='y3n8r'></center></pre></bdo></b><th id='y3n8r'></th></span></q></dt></tr></i><div class="o4ybwga" id='y3n8r'><tfoot id='y3n8r'></tfoot><dl id='y3n8r'><fieldset id='y3n8r'></fieldset></dl></div>

        <legend id='y3n8r'><style id='y3n8r'><dir id='y3n8r'><q id='y3n8r'></q></dir></style></legend>
      1. <small id='y3n8r'></small><noframes id='y3n8r'>

        • <bdo id='y3n8r'></bdo><ul id='y3n8r'></ul>

        Laravel 高級(jí)搜索查詢(xún)修復(fù)

        Laravel advanced search query fix(Laravel 高級(jí)搜索查詢(xún)修復(fù))

          <tbody id='Zta7q'></tbody>

      2. <tfoot id='Zta7q'></tfoot>
      3. <small id='Zta7q'></small><noframes id='Zta7q'>

              <legend id='Zta7q'><style id='Zta7q'><dir id='Zta7q'><q id='Zta7q'></q></dir></style></legend>
                • <bdo id='Zta7q'></bdo><ul id='Zta7q'></ul>

                  <i id='Zta7q'><tr id='Zta7q'><dt id='Zta7q'><q id='Zta7q'><span id='Zta7q'><b id='Zta7q'><form id='Zta7q'><ins id='Zta7q'></ins><ul id='Zta7q'></ul><sub id='Zta7q'></sub></form><legend id='Zta7q'></legend><bdo id='Zta7q'><pre id='Zta7q'><center id='Zta7q'></center></pre></bdo></b><th id='Zta7q'></th></span></q></dt></tr></i><div class="nv5yxhn" id='Zta7q'><tfoot id='Zta7q'></tfoot><dl id='Zta7q'><fieldset id='Zta7q'></fieldset></dl></div>
                  本文介紹了Laravel 高級(jí)搜索查詢(xún)修復(fù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)包含多個(gè)輸入和選擇框的搜索表單,我需要幫助來(lái)獲取查詢(xún)中的條件,以便每個(gè)部分單獨(dú)工作并同時(shí)工作.

                  這是我的刀片代碼:

                  {{csrf_field()}}<div class="sidebar-title"><span>高級(jí)搜索</span><i class="fa fa-caret-down show_sidebar_content" aria-hidden="true"></i>

                  <!-- ./sidebar-title --><div id="tags-filter-content" class="sidebar-content"><div class="filter-tag-group">@foreach($options 作為 $option)<div class="tag-group"><p class="title"><span class="filter-title show_filter_content">{{$option->title}} <span class="pull-right"><i class="fa fa-minus"></i></span></span></p><div class="filter-content"><div class="checkbox">@foreach($option->suboptions as $suboption)<label for="suboptions"><input name="suboptions[]" type="checkbox" value="{{$suboption->id}}">{{ucfirst($suboption->title)}}@endforeach

                  @endforeach<!-- ./tag-group --><div class="tag-group"><p class="title"><span class="filter-title show_filter_content">品牌<span class="pull-right"><i class="fa fa-minus"></i></span><;/span></p><div class="filter-content"><div class="checkbox">@foreach($brands 作為 $brand)<label for="brands"><input name="brands[]" type="checkbox" value="{{$brand->id}}">{{$brand->title}}@endforeach

                  <!-- ./tag-group --><div class="tag-group"><p class="title"><span class="filter-title show_filter_content">價(jià)格范圍<span class="pull-right"><i class="fa fa-minus"></i></span></span></p><div class="row filter-content"><div class="col-md-6"><div class="form-group"><label for="min_price" hidden>Min</label><input type="text" name="min_price" class="form-control" placeholder="Rp Min">

                  <div class="col-md-6"><div class="form-group"><label for="max_price" hidden>Max</label><input type="text" name="max_price" class="form-control" placeholder="Rp Max">

                  <!-- 標(biāo)簽組--><div class="text-center mt-20"><button type="submit" class="btn btn-danger">TERPAKAN</button>

                  </div><!-- ./filter-tag-group --></div><!-- ./sidebar-content --></表單>

                  這是我的路線:

                  Route::post('/advanced-search', 'frontendSearchController@filter')->name('advancesearch');

                  最后我的函數(shù)代碼是:

                  公共函數(shù)advancedsearch(Request $request) {$brands = Brand::all();//用于頁(yè)面的其他部分.(與搜索功能無(wú)關(guān))$options = Option::all();//用于頁(yè)面的其他部分.(與搜索功能無(wú)關(guān))$suboptions = DB::table('product_suboption');//我的 product_id 和 subopyion_id 保存在哪里//搜索功能$products = Product::where(function($query){//獲取輸入$suboptions2 = Input::has('suboptions') ?Input::get('suboptions') : [];$min_price = Input::has('min_price') ?Input::get('min_price') : null;$max_price = Input::has('max_price') ?Input::get('max_price') : null;$brands2 = Input::has('brands') ?Input::get('brands') : [];//返回結(jié)果$query->where('price','>=',$min_price)->where('price','<=',$max_price);})->get();return view('front.advancesearch', compact('products', 'brands', 'options'));}

                  我的模特關(guān)系:

                  product 型號(hào):

                  公共函數(shù)選項(xiàng)(){返回 $this->belongsToMany(Option::class);}公共功能子選項(xiàng)(){返回 $this->belongsToMany(Suboption::class, 'product_suboption', 'product_id', 'suboption_id');}公共功能品牌(){返回 $this->belongsTo(Brand::class);}

                  Option 模型:

                  公共函數(shù)子選項(xiàng)(){返回 $this->hasMany(Suboption::class, 'option_id');}公共功能產(chǎn)品(){返回 $this->belongsToMany(Product::class);}

                  子選項(xiàng)模型:

                  公共函數(shù)選項(xiàng)(){返回 $this->belongsTo(Option::class, 'option_id');}公共功能產(chǎn)品(){返回 $this->belongsToMany(Product::class);}

                  品牌型號(hào):

                  公共功能產(chǎn)品(){返回 $this->hasMany(Product::class);}

                  注意

                  我的 brands 搜索來(lái)自產(chǎn)品表,其中每個(gè)產(chǎn)品都有 brand_id 列.

                  但是

                  我的 suboptions 來(lái)自名為 product_suboption 的第三個(gè)表(如您在我的模型代碼中看到的),我在其中保存了 product_idsuboption_id.

                  解決方案

                  SOLVED

                  在玩了數(shù)周的代碼之后,我終于為自己找到了正確的結(jié)果(在我的情況下,它對(duì)其他人有效,可能適用于其他建議的答案)

                  公共函數(shù)advancedsearch(Request $request) {$options = Option::all();$brands = Brand::all();$brandss = Input::has('brands') ?Input::get('brands') : [];$suboption = Input::has('suboptions') ?(int)Input::get('suboptions') : [];$min_price = Input::has('min_price') ?(int)Input::get('min_price') : null;$max_price = Input::has('max_price') ?(int)Input::get('max_price') : null;//代碼if(count($request['suboptions'])){$products = DB::table('products')->join('product_suboption', function ($join) {$suboption = Input::has('suboptions') ?Input::get('suboptions') : [];$join->on('products.id', '=', 'product_suboption.product_id')-> where('product_suboption.suboption_id', '=', $suboption);})-> 分頁(yè)(12);}elseif(count($request['brands'])){$products = DB::table('products')->whereIn('products.brand_id', $brandss)-> 分頁(yè)(12);}elseif(count($request['min_price']) && count($request['max_price'])){$products = DB::table('products')->whereBetween('price', [$min_price, $max_price])-> 分頁(yè)(12);}return view('front.advancesearch', compact('products', 'brands', 'options'));}

                  <塊引用>

                  注意:我的大部分定價(jià)問(wèn)題都是用 (int) 解決的,正如你在我的代碼中看到的 (int)Input::get('min_price')(int)Input::get('max_price').

                  特別感謝 Ravindra Bhandericount($request[''] 建議.

                  I have a search form with multiple input and select boxes I need help to get if conditions in my query in order to each part works separately and all at once.

                  here is my blade codes:

                  <form action="{{route('advancesearch')}}" method="post">
                        {{csrf_field()}}
                        <div class="sidebar-title">
                          <span>Advanced Search</span>
                          <i class="fa fa-caret-down show_sidebar_content" aria-hidden="true"></i>
                        </div>
                        <!-- ./sidebar-title -->
                  
                        <div id="tags-filter-content" class="sidebar-content">
                          <div class="filter-tag-group">
                  
                            @foreach($options as $option)
                            <div class="tag-group">
                              <p class="title">
                                <span class="filter-title show_filter_content">{{$option->title}} <span class="pull-right"><i class="fa fa-minus"></i></span></span>
                              </p>
                              <div class="filter-content">
                                <div class="checkbox">
                                @foreach($option->suboptions as $suboption)
                                <label for="suboptions">
                                  <input name="suboptions[]" type="checkbox" value="{{$suboption->id}}">
                                  {{ucfirst($suboption->title)}}
                                </label>
                                @endforeach
                              </div>
                            </div>
                            </div>
                            @endforeach
                            <!-- ./tag-group -->
                  
                            <div class="tag-group">
                              <p class="title">
                                <span class="filter-title show_filter_content">Brand <span class="pull-right"><i class="fa fa-minus"></i></span></span>
                              </p>
                              <div class="filter-content">
                                <div class="checkbox">
                                @foreach($brands as $brand)
                                <label for="brands">
                                  <input name="brands[]" type="checkbox" value="{{$brand->id}}">
                                  {{$brand->title}}
                                </label>
                                @endforeach
                              </div>
                            </div>
                            </div>
                            <!-- ./tag-group -->
                  
                            <div class="tag-group">
                              <p class="title">
                                <span class="filter-title show_filter_content">Price Range <span class="pull-right"><i class="fa fa-minus"></i></span></span>
                              </p>
                              <div class="row filter-content">
                                <div class="col-md-6">
                                  <div class="form-group">
                                    <label for="min_price" hidden>Min</label>
                                    <input type="text" name="min_price" class="form-control" placeholder="Rp Min">
                                  </div>
                                </div>
                                <div class="col-md-6">
                                  <div class="form-group">
                                    <label for="max_price" hidden>Max</label>
                                    <input type="text" name="max_price" class="form-control" placeholder="Rp Max">
                                  </div>
                                </div>
                              </div>
                            </div>
                            <!-- tag-group -->
                  
                            <div class="text-center mt-20">
                              <button type="submit" class="btn btn-danger">TERPAKAN</button>
                            </div>
                  
                          </div><!-- ./filter-tag-group -->
                        </div><!-- ./sidebar-content -->
                      </form>
                  

                  and this is my route:

                  Route::post('/advanced-search', 'frontendSearchController@filter')->name('advancesearch');
                  

                  finally my function code is:

                  public function advancedsearch(Request $request) {
                          $brands = Brand::all(); // uses for other part of the page. (not related to search function)
                          $options = Option::all(); // uses for other part of the page. (not related to search function)
                          $suboptions = DB::table('product_suboption'); // where my product_id and subopyion_id saves
                  
                          //search function
                          $products = Product::where(function($query){
                              //getting inputs
                              $suboptions2 = Input::has('suboptions') ? Input::get('suboptions') : [];
                              $min_price = Input::has('min_price') ? Input::get('min_price') : null;
                              $max_price = Input::has('max_price') ? Input::get('max_price') : null;
                              $brands2 = Input::has('brands') ? Input::get('brands') : [];
                  
                              //returning results
                              $query->where('price','>=',$min_price)
                                      ->where('price','<=',$max_price);
                              })->get();
                  
                          return view('front.advancesearch', compact('products', 'brands', 'options'));
                      }
                  

                  My models relations:

                  product model:

                  public function options(){
                       return $this->belongsToMany(Option::class);
                    }
                    public function suboptions(){
                       return $this->belongsToMany(Suboption::class, 'product_suboption', 'product_id', 'suboption_id');
                    }
                  public function brand(){
                       return $this->belongsTo(Brand::class);
                    }
                  

                  Option model:

                  public function suboptions(){
                       return $this->hasMany(Suboption::class, 'option_id');
                    }
                  
                    public function products(){
                       return $this->belongsToMany(Product::class);
                    }
                  

                  Suboption model:

                  public function option(){
                       return $this->belongsTo(Option::class, 'option_id');
                    }
                  
                    public function products(){
                       return $this->belongsToMany(Product::class);
                    }
                  

                  Brand model:

                  public function products(){
                       return $this->hasMany(Product::class);
                  }
                  

                  note

                  My brands search is coming from products table where I have column brand_id for each product.

                  BUT

                  My suboptions come from 3rd table named product_suboption (as you see in my models codes) where i save product_id and suboption_id.

                  解決方案

                  SOLVED

                  After weeks of playing with codes finally I came to the right results for myself (in my case it works this way for others maybe works with other suggested answers)

                  public function advancedsearch(Request $request) {
                      $options = Option::all();
                      $brands = Brand::all();
                      $brandss = Input::has('brands') ? Input::get('brands') : [];
                      $suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : [];
                      $min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
                      $max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
                  
                      //codes
                      if(count($request['suboptions'])){
                        $products = DB::table('products')
                        ->join('product_suboption', function ($join) {
                          $suboption = Input::has('suboptions') ? Input::get('suboptions') : [];
                              $join->on('products.id', '=', 'product_suboption.product_id')
                                   ->where('product_suboption.suboption_id', '=', $suboption);
                          })
                        ->paginate(12);
                      }
                  
                      elseif(count($request['brands'])){
                        $products = DB::table('products')
                        ->whereIn('products.brand_id', $brandss)
                        ->paginate(12);
                      }
                  
                      elseif(count($request['min_price']) && count($request['max_price'])){
                        $products = DB::table('products')
                        ->whereBetween('price', [$min_price, $max_price])
                        ->paginate(12);
                      }
                  
                  
                      return view('front.advancesearch', compact('products', 'brands', 'options'));
                      }
                  

                  NOTE: most of my pricing issues solved with (int) as you see in my codes (int)Input::get('min_price') and (int)Input::get('max_price').

                  Special thanks to Ravindra Bhanderi for his count($request[''] suggestion.

                  這篇關(guān)于Laravel 高級(jí)搜索查詢(xún)修復(fù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語(yǔ)句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶(hù)獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無(wú)法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢(xún):用查詢(xún)結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶(hù)“root@“l(fā)ocalhost的訪問(wèn)被拒絕)
                • <tfoot id='fagtN'></tfoot><legend id='fagtN'><style id='fagtN'><dir id='fagtN'><q id='fagtN'></q></dir></style></legend>

                      <small id='fagtN'></small><noframes id='fagtN'>

                      <i id='fagtN'><tr id='fagtN'><dt id='fagtN'><q id='fagtN'><span id='fagtN'><b id='fagtN'><form id='fagtN'><ins id='fagtN'></ins><ul id='fagtN'></ul><sub id='fagtN'></sub></form><legend id='fagtN'></legend><bdo id='fagtN'><pre id='fagtN'><center id='fagtN'></center></pre></bdo></b><th id='fagtN'></th></span></q></dt></tr></i><div class="ckcu5pg" id='fagtN'><tfoot id='fagtN'></tfoot><dl id='fagtN'><fieldset id='fagtN'></fieldset></dl></div>
                      • <bdo id='fagtN'></bdo><ul id='fagtN'></ul>

                      主站蜘蛛池模板: KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 鹤壁创新仪器公司-全自动量热仪,定硫仪,煤炭测硫仪,灰熔点测定仪,快速自动测氢仪,工业分析仪,煤质化验仪器 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 切铝机-数控切割机-型材切割机-铝型材切割机-【昆山邓氏精密机械有限公司】 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 披萨石_披萨盘_电器家电隔热绵加工定制_佛山市南海区西樵南方综合保温材料厂 | 大数据营销公司_舆情监测软件_上海SEO公司-文军营销官网 | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 电子元器件呆滞料_元器件临期库存清仓尾料_尾料优选现货采购处理交易商城 | 南京精锋制刀有限公司-纵剪机刀片_滚剪机刀片_合金刀片厂家 | Honsberg流量计-Greisinger真空表-气压计-上海欧臻机电设备有限公司 | 喷播机厂家_二手喷播机租赁_水泥浆洒布机-河南青山绿水机电设备有限公司 | 工业CT-无锡璟能智能仪器有限公司| 体坛网_体坛+_体坛周报新闻客户端| 工业铝型材-铝合金电机壳-铝排-气动执行器-山东永恒能源集团有限公司 | 渗透仪-直剪仪-三轴仪|苏州昱创百科| 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 电磁铁_推拉电磁铁_机械手电磁吸盘电磁铁厂家-广州思德隆电子公司 | 北京三友信电子科技有限公司-ETC高速自动栏杆机|ETC机柜|激光车辆轮廓测量仪|嵌入式车道控制器 | 压滤机滤板_厢式_隔膜_板框压滤机滤板厂家价格型号材质-大凯环保 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 水冷散热器_水冷电子散热器_大功率散热器_水冷板散热器厂家-河源市恒光辉散热器有限公司 | 刺绳_刀片刺网_刺丝滚笼_不锈钢刺绳生产厂家_安平县浩荣金属丝网制品有限公司-安平县浩荣金属丝网制品有限公司 | 双段式高压鼓风机-雕刻机用真空泵-绍兴天晨机械有限公司 | 伺服电机_直流伺服_交流伺服_DD马达_拓达官方网站 | 自动记录数据电子台秤,记忆储存重量电子桌称,设定时间记录电子秤-昆山巨天 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 汕头市盛大文化传播有限公司,www.11400.cc | 硅PU球场、篮球场地面施工「水性、环保、弹性」硅PU材料生产厂家-广东中星体育公司 | 复合肥,化肥厂,复合肥批发,化肥代理,复合肥品牌-红四方 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 校服厂家,英伦校服定做工厂,园服生产定制厂商-东莞市艾咪天使校服 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 选矿设备-新型重选设备-金属矿尾矿重选-青州冠诚重工机械有限公司 | 郑州墨香品牌设计公司|品牌全案VI设计公司 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 |