dimanche 31 mars 2019

Appending Query String with multiple filters

I have a filter bar that searches one filter at a time, however I would like for it to select multiple filters at once, my links for the filters all currently have a single query string, but is there a way to append the query string with another query?

Currently I set up my filters like so in the code below in my Controller

$products = new Product;


        $queries = [];

        $columns = [
            'beertype_id', 'packaging', 'brewery_id'
        ];

        foreach ($columns as $column){
            if (request()->has($column)){

            $products = $products->where($column, request($column));

                $queries[$column] = request($column);
        }


        }

        $products = $products->paginate(10)->appends($queries);

And then call them in the blade template like so

<p>Filter Products:</p>

       <a href="/products">Reset</a>

        <ul>
            <p>Types of Beer:</p>

            <li class="filter-link"><a href="/products?beertype_id=1" >IPA</a></li>
            <li class="filter-link"><a href="/products?beertype_id=2">Lager</a></li>
            <li class="filter-link"><a href="/products?beertype_id=3">Pale Ale</a></li>
        </ul>

         <ul>
            <p>Packaging:</p>
             <li class="filter-link"><a href="/products?packaging=bottle">Bottle</a></li>
             <li class="filter-link"><a href="/products?packaging=can">Can</a></li>
             <li class="filter-link"><a href="/products?packaging=keg">Keg</a></li>
         </ul>

         <ul>
             <p>Brewery:</p>

             <li class="filter-link"><a href="/products?brewery_id=2">Kinnegar</a></li>
             <li class="filter-link"><a href="/products?brewery_id=3">White Hag</a></li>
             <li class="filter-link"><a href="/products?brewery_id=4">Quilmes</a></li>

         </ul>

What I would like to do is end up with a query string like ?beertype_id=3&beertype_id=5&brewery_id=2 etc, how could I do this? Any help would be greatly appreciated!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OADCMx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire