sumitgroup
3 months ago
469
3
Laravel

How i Can Filter the Price from two column in Laravel 6?

Posted 3 months ago by sumitgroup

I am getting error in filters, i have 2 columns in my database, one is minprice and another is maxprice and now i want to filter data from these 2 columns. Suppose i want price between 1000000-6000000 then it should be show the exact values between these prices. I have already written a a code for this but i am not understanding where i am mistaking.

Here are my controller code...

public function homefilter(Request $r){
  $minPrice= $r->minPrice;
  $maxPrice= $r->maxPrice;
  if($r->price_range){
    $price_range = explode('-', $r->price_range);
    $minPrice= $price_range[0];
    $maxPrice= $price_range[1];
}
 $prop = Property::active()
  ->when($minPrice, function($q) use($minPrice,$maxPrice){
    return $q->whereHas('proDetail', function($sq) use($minPrice,$maxPrice){
        $sq->where([
            ['minprice','>=', $minPrice],
            ['maxprice','<=', $maxPrice]
        ]);
    }); 
})  
->without('builder')
 ->paginate('15');
return view('search', compact('prop','allCategory','cities','req'));
 }

and here are my view file data...

  <div class="panel-body">
                                                <ul class="list-group">
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="1000000-6000000">Under 60 Lac</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="6000000-8000000">60 -80 Lac</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="8000000-10000000">80 - 1 Cr.</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="10000000-15000000">1 - 1.50 Cr.</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="15000000-20000000">1.50 - 2 Cr.</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="20000000-25000000">2 -2.5 Crore</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="25000000-30000000">2.5 - 3 Crore</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="30000000-50000000">3 - 5  Crore</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="50000000-100000000">5 - 10 Crore</li>
                                                    <li class="list-group-item-filter"><input type="checkbox" name="price_range" value="50000000-100000000">10 Crore +</li>                                     
                                                </ul>
                                            </div>

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