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

samalapsy's avatar

Search with Array Multiple Parameters

I have an advanced search implementation on my website, where I have to display the selected or checked items (from a checkbox) on th url, please how can I achieve this and also how can I remove _token from the search parameters.

Thanks You

0 likes
7 replies
jlrdw's avatar

Something like https://drive.google.com/file/d/0B1_PFw--3o74YjVreHNBOWU2aEE/view

Just add querystring parameters or pass parameters via route to the where clause in query

Looks something like

        $query = Dog::where('dogname', 'like', $dogsch);
        if ($aval == "n") {
            $query->where('adopted', '=', 1);
        } else if ($aval == "y") {
            $query->where('adopted', '=', 0);
        }
        $dogs = $query->orderBy('lastedit', 'DESC')->paginate(5);
        $pagelinks = array('psch' => $dogsearch, 'aval' => $aval);

Just build up the query as needed.

tykus's avatar

You want the search query and/or filters to be sent as a query string; just make your search form send a GET request (and make sure your route definition responds to GET:

<form method="GET" action="">
    
</form>

It will not require a token.

jlrdw's avatar

@tykus hope OP doesn't take literally

<form method="GET" action="">
    
</form>

Is all that's needed. Couldn't help myself, in joking mood tonight.

samalapsy's avatar

Thi is the request parameters i'm sending via get

array:4 [
  "budget" => "5000"
  "room_type" => "Single Rooms"
  "amenities" => array:3 [
    0 => "Beds in room"
    1 => "Running Water"
    2 => "Wardrobe"
  ]
  "proximity" => "Very Close"
]

This is what I have in my url

http://localhost/prj/public/search/advanced?budget=5000&room_type=Single+Rooms&amenities%5B%5D=Beds+in+room&amenities%5B%5D=Running+Water&amenities%5B%5D=Wardrobe&proximity=Very+Close

How can I make this URL a Clean and SEO friendly one

jlrdw's avatar

Using parameters. Look at route parameters in docs.

samalapsy's avatar

This is how my route looks like

Route::any('/filter?room={room}&budget={budget}&proximity={$proximity}&amenities={amenities}', 'SearchController@advancedSearch')->name('advanced_search');
jlrdw's avatar

NO NO NO if you are using querystring you don't do all that mess.

Route::any('filter, 'SearchController@advancedSearch');

Is all you need, because querystring is passed anyway.

Then in controller

$request->input('budget')
etc

This parameter thing

room={room}/  etc

Is for passing parameters when NOT USING querystring

Like

public function advancedSearch(Request $request, $budget = null, etc)

You really need to take time off from laravel and learn basic request / response.

Also I would use POST for the search.

Also see this for optional parameters. https://laracasts.com/discuss/channels/laravel/bug-passing-optional-parameters-to-controllers-doesnt-work

Please or to participate in this conversation.