sumitgroup
3 months ago
216
0
Laravel

Error in Drop down filter in Laravel?

Posted 3 months ago by sumitgroup

I am trying to filter data from 2 dropdown, but when i selecting 'project typethen it's filter correctly, but if i am selectingstatusand 'project type together, then it's not filtering.

here are my controller code..

public function homefilter(Request $r){
  $propCat= $r->propCat;
  $possession= $r->consStatus;
 $prop = Property::active()
  ->when($possession, function($q) use($possession){
    return $q->whereHas('proDetail', function($sq) use($possession){ 
        $sq->where('possession', "like", "%" .$possession[0]. "%");
        for($i=1; $i<count($possession); $i++){
           $sq->orWhere('possession', "like", "%" .$possession[$i]. "%");
       }
   });
})
  ->when($propCat, function ($q) use ($propCat) {
    return $q->where(function ($sq) use ($propCat) {
        $sq->whereHas('proCat', function($sq) use($propCat){
            $sq->where('catId', 3)
            ->where('subCatId', $propCat);
        });
    });
  })
 ->without('builder')
->paginate('15');
 return view('search', compact('prop','allCategory','cities','req'));

And here are my view code...

<form class="hero__form v1 filter listing-filter" id="filterForm" method="POST" action="{{route('filter.property')}}">
      @csrf
 <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="New Launch">New Launch</option>
            <option value="Ready To Move">Ready To Move</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 class="hero__form-input  custom-select" name="propCat[]">
            <option>Project Type</option>
            @foreach($allCategory as $sCat)   
            <option value="{{ $sCat->subCatId }}">{{ $sCat->cat_name }}</option>
            @endforeach
          </select>
        </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>
</form>

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