久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" id='fagtN'><tfoot id='fagtN'></tfoot><dl id='fagtN'><fieldset id='fagtN'></fieldset></dl></div>
                      • <bdo id='fagtN'></bdo><ul id='fagtN'></ul>

                      主站蜘蛛池模板: 一级黄色片在线看 | 精品一区二区三区在线观看国产 | 一区二区三区观看视频 | 亚洲成在线观看 | 国产日韩视频 | 日韩一区在线观看视频 | 欧美日韩国产精品激情在线播放 | 午夜精品久久久久久不卡欧美一级 | 国产综合视频 | 精品一区久久 | 国产一区二区在线播放 | 免费能直接在线观看黄的视频 | 日韩成人在线免费视频 | 中文字幕第十页 | 91麻豆精品国产91久久久久久 | 香蕉视频黄色 | 成人午夜精品 | 国产在线精品一区二区 | 欧美精品1区 | 国产欧美一区二区久久性色99 | 日本精品久久久久 | 97伦理电影网 | 亚洲国产精品一区在线观看 | 欧美又大粗又爽又黄大片视频 | 精品一区免费 | 狼色网| 国产激情视频在线观看 | 精品一区二区三区免费毛片 | 午夜精品视频在线观看 | 国产 日韩 欧美 制服 另类 | 亚洲天堂一区二区 | 亚洲www啪成人一区二区麻豆 | 卡通动漫第一页 | 九九热精品在线视频 | 久久久在线视频 | 日日操操 | 国产激情在线看 | 亚洲欧美在线观看 | 91亚洲视频在线 | av大全在线 | 久久久久久亚洲 |