Header Ads

Header ADS

laravel product price range and after filter min & max value keep

  //product filter by Price range

  Route::post('/filter', 'filterByPrice')->name('products.filterByPrice');

 public function filterByPrice(Request $request)
    {
        $minPrice = $request->input('min_price');
        $maxPrice = $request->input('max_price');

        $products = Product::whereBetween('selling_price', [$minPrice, $maxPrice])->get();

        return view('front.product.shop', compact('products','minPrice','maxPrice'));

    } //end method

 <div class="price-range">
                        <form action="{{ route('products.filterByPrice') }}" method="post">
                            @csrf
                            <h3>Product Price Range</h3>
                            <label for="min-price">Minimum Price:</label>
                            <input type="range" id="min-price" min="0" max="10000" step="10" name="min_price" value="{{ isset($minPrice) ? $minPrice : 0 }}">
                            <span id="min-price-value">${{ isset($minPrice) ? $minPrice : 0 }}</span>
                            <br>
                            <label for="max-price">Maximum Price:</label>
                            <input type="range" id="max-price" min="0" max="10000" step="10" name="max_price" value="{{ isset($maxPrice) ? $maxPrice : 10000 }}">
                            <span id="max-price-value">${{ isset($maxPrice) ? $maxPrice : 10000 }}</span>
                            <br><br>
                            <button type="submit" class="btn btn-warning text-light">Apply Filter</button>
                        </form>
                    </div>

No comments

Theme images by fpm. Powered by Blogger.