mercredi 14 avril 2021

Items Filtering

Am trying to make a eCommorece project and I want to add filter dropmenues on the products table, to search from more than one database, but everytime I select an option I get this error below...

https://flareapp.io/share/v5pzQz2P

And here is the conde on the controller

$products = Product::orderBy('id', 'desc')
        ->where( function($query) use($request){
            return $request->status_id ?
                $query->from('products')->where('status',$request->status_id) : '';})
        ->where( function($query) use($request){
            return $request->category_id ?
                $query->from('product_categories')->where('category_id',$request->category_id) : '';})
        ->paginate(30);
        
        $selected_id = [];
        $selected_id['status_id'] = $request->status_id;
        $selected_id['category_id'] = $request->category_id;

        return view('dashboard.products.index', compact('products', 'selected_id'), $data);

My blade view

form class="col-sm-5 px-2" action="" method="GET">
                @csrf
                <select class="form-select form-select-sm" name="status_id" aria-label="Bulk actions" onchange="this.form.submit()">
                  <option value="0" >All Products</option>
                  <option value="00" >Disabled Products</option>
                  <option value="1" >Enabled Products</option>
                </select>
              </form>
              <form class="col-sm-5" action="" method="GET">
                @csrf
                <select class="form-select form-select-sm" name="category_id" aria-label="Bulk actions" onchange="this.form.submit()">
                  <option value="0" >All Products</option>
                  <option value="1" >11223123</option>
                </select>
              </form>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire