根据价格过滤laravel

I would like to know how can I make price filter in my application?

I'm using laravel 5.4

I currently have something like this:

public function indexproduct(Request $request) {
      $query = Product::orderBy('created_at','desc');
      if($request->keyword){
          // This will only executed if you received any keyword
          $query = $query->where('title','like','%'.$keyword.'%');
      }
      if($request->min_price && $request->max_price){
          // This will only executed if you received any price
          // Make you you validated the min and max price properly
          $query = $query->where('price','>=',$request->min_price);
          $query = $query->where('price','<=',$request->max_price);
      }
      $products = $query->paginate(6);
      return view('frontend.shop', compact('products'));
    }

View:

<form class="form-inline" action="{{route('shop')}}" method="GET">
          Min <input class="form-control" type="text" name="min_price">
          Max <input class="form-control" type="text" name="max_price">
          Keyword <input class="form-control" type="text" name="keyword" >
          <input class="btn btn-default" type="submit" value="Filter">
      </form>

Which will show my products. I also want to add filter select box in top of my products to let users filter the results.

Update: now will load the page but no result, it sort of just refresh the page!

database

First of all, You should create a form where you can put all your filters.

<form action="{{ url('url/to/your/indexproduct')}}" method="GET">
    <input type="text" name="min_price">   //User can input minimum price here
    <input type="text" name="max_price">  //User can input maximun price here
    <input type="text" name="keyword" >  // User can input name or description
    <input type="submit" value="Filter">
</form>

After that, Your controller will receive data from that form after clicking submit button. So if you want to check it. Do it like this.

public function indexproduct(Illuminate\Http\Request $request) {
    dd($request->all())  // This will show all your filters
}

Then when you are that your data was sent to your controller, you should revise your query and include your filter. (There so many way to do that but this is a simple one)

public function indexproduct(Illuminate\Http\Request $request) {
    $query = Product::orderBy('created_at','desc');
    if($request->keyword){
        // This will only execute if you received any keyword
        $query = $query->where('name','like','%'.$keyword.'%');
    }
    if($request->min_price && $request->max_price){
        // This will only execute if you received any price
        // Make you you validated the min and max price properly
        $query = $query->where('price','>=',$request->min_price);
        $query = $query->where('price','<=',$request->max_price);
    }
    $products = $query->paginate(5);
    return view('frontend.shop', compact('products'));
}

I hope it'll help you.