sumitgroup
3 months ago
234
1
Laravel

Getting Error in Search Filter in Laravel 6?

Posted 3 months ago by sumitgroup

I am getting error in my search filter, everything is working fine but when i am searching by project Type, Select Status and Search by Project name then it's showing 0 results. But if i am not selecting any drop down fields it's working perfect. Please let me know where is the mistake.

Note: If i select and drop down fields and then enter project name then it's showing 0 results. Both drop down working fine without search bar.

here are my route...

Route::match(['get', 'post'], '/filter','[email protected]')->name('property.filter');

Hera are my controller code....

public function searchProperty(Request $r)
      {
$cat=$r->category;
$possession= $r->consStatus;
$prop_name= $r->prop_name;
prop=Listing::latest()
        ->when($prop_name, function($q) use($prop_name){
          return $q->whereHas('property.listing', function($sq) use($prop_name){ 
            $sq->where('prop_name', "like", "%" .$prop_name. "%");
          });
        })
->when($cat, function($q) use($cat){
          return $q->whereHas('property.listing', function($sq) use($cat){ 
            $sq->where('category', "like", "%" .$cat[0]. "%");
            for ($i=1; $i<count($cat); $i++) {
              $sq->orWhere('category', "like", "%" .$cat[$i]. "%");
            }
          });
        })
->when($possession, function($q) use($possession){
          return $q->whereHas('property.proDetail', function($sq) use($possession){ 
            $sq->where('possession', "like", "%" .$possession[0]. "%");
            for($i=1; $i<count($possession); $i++){
             $sq->orWhere('possession', "like", "%" .$possession[$i]. "%");
           }
         });
        })
->without('builder')
    ->paginate('100');

Herea are my view code..

    <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
      <form class="hero__form v1 filter listing-filter" id="filterForm1" method="POST" action="{{route('property.filter')}}">
        @csrf
        <div class="row">
          <div class="col-xl-2 col-lg-6 col-md-6 col-sm-12 col-12 py-3 pl-30 pr-0">
            <select class="hero__form-input  custom-select" name="category[]" id="idPropertyType">
              <option>Project Type</option>
              <option value="Residential">Residential</option>
              <option value="Commercial">Commercial</option>
            </select>
          </div>
          <div class="col-xl-2 col-lg-6 col-md-6 col-sm-12 col-12 py-3 pl-30 pr-0">
            <select name="consStatus[]" class="hero__form-input  form-control custom-select">
              <option value="">Select Status</option>
              <option value="Under Construction">Under Construction</option>
              <option value="Ready To Move">Ready To Move</option>
            </select>
          </div>
          <div class="col-xl-5 col-lg-6 col-md-6 col-sm-12 col-12 py-3 pl-30 pr-0">
           <div class="input-search">
            <input type="text" name="prop_name" placeholder="Search by Project Name.." id="search_field place-event" onkeyup="getSearchResult1(this.value)" autocomplete="off">
            <input type="hidden" name="lstId">
            <input type="hidden" name="prop_name">
            <!-- <input type="hidden" name="ls_fs"> -->
            <input type="hidden" name="suggestion">
            <div class="dropdwonlist">  
              <ul class="list-group" id="suggetResult1">               
              </ul>
            </div> 
          </div>
        </div>
        <div class="col-xl-3 col-lg-6 col-md-6 col-sm-12 col-12 py-3 pl-30 pr-0">
          <div class="submit_btn">
            <button class="btn v3" type="submit">Search</button>
          </div>
        </div>
      </div>
    </form>
  </div>

Please sign in or create an account to participate in this conversation.