3 months ago

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)
$possession= $r->consStatus;
$prop_name= $r->prop_name;
        ->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]. "%");

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')}}">
        <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>
          <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>
          <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">               
        <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>

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