Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eddy1992's avatar

Query Strings

Hi I am trying to make a filter for e commerce website. I have two kinds of filters one is for brands and one is for price. I want to pass query string in the url so that I could get those values. I wanted to know how would I pass query string in the url after a click of a checkbox in the view and also wanted to know what would be the best method to pass an array of values example when the user checks on multiple brands then how would I pass the array of those brand_id to the query string.

Please assist Thank you

0 likes
2 replies
accent-interactive's avatar

You can get the params from the request like so `$params = request()->all();‘

For a single parameter: $foo = request()->get('foo');

Passing the query string is easiest done by passing an associative array to a named route, as parameters:

public function index (Request $request) {
    $params = $request->all()(

    // Do stuff

    return redirect(route('some.route', $params));
}

Dealing with an array of values is as simple as dividing them with a comma like so: ?brands=brand_one,brand_two

Use the values in your code by exploding it on a comma: $brands = explode(',', request()->get('brands');

kahriman's avatar

you need to name the input field correctly to pass arrays.

View:

input type="checkbox" name="brands[]" value="brand_id"

Controller:


    $brands = $request->get('brands');

Please or to participate in this conversation.