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

esyi78's avatar

remove parameter from url

I have my route that have multiple sorting like ?country=usa&name=Johndoe&car=volvo

I would like to have dropdown with link to select with county or name or car without effecting the other parameter that I have already in the url how to that in blade?

thanks

0 likes
8 replies
Insperio's avatar

I think you just need a standard GET form and then you just pass currently selected parameters to blade and set them as "selected"

E.g in your controller

$country = Input::get('country');
$countries_list = ['usa', 'uk', 'germany']

and then just pass those variables to your view as usual.

In your blade file you write something like this:

@foreach($countries_list as $c)
@if($c == $country)
<option selected="selected">{{$c->name}}</option>
@else
<option>{{$c->name}}</option>
@endif
@endforeach
esyi78's avatar

hi I research it and see that it have to do that with js (https://usefulangle.com/post/81/javascript-change-url-parameters) to change the parameter

and in your controller you put a "when" function for each parameter (Laravel https://laravel.com/docs/5.8/queries#conditional-clauses)

but I couldn't figure out how to search in the controller when you have other parameter in the url and you want also to search

in the controller

        $city = $request->input('city');
        $sortby = $request->input('orderby');
        $search = $request->input('search');

        $records = Record::
                when($city, function ($query, $city) {
                    return $query->where('city', $city);
                })->
                when($sortby, function ($query, $sortby) {
                    return $query->orderBy($sortby);
                })->
                when($search, function ($query, $search) {
                    return $query->search($search);
                })
                ->get();

this don't work getting error. Call to undefined method Illuminate\Database\Eloquent\Builder::search any idea?

Snapey's avatar

search is not an eloquent function

esyi78's avatar

@snapey I know from the error

but just want to clarify that they're isn't any way to combine with other parameter?

only search in the parameter I can do record::search($search)->get() but together with other parameter I want to know if you can combine?

thanks

esyi78's avatar

ok as I experience if somebody is interested their is now way to do that with search on sever side you can do it with algolia on client side Laravel scout documentation

Scout allows you to add simple "where" clauses to your search queries. Currently, these clauses only support basic numeric equality checks,...

Snapey's avatar

What are you on about?

You think its not possible to search in a database?

yibr's avatar

@snapey not with query builder and also search with scout

if otherwise tell me

you can manually do that

jlrdw's avatar

Of course you can build a search and pass parameters:

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

You have to pass the "filters" in the url or query string. HTTP and HTML 101.

Also see

https://laracasts.com/discuss/channels/laravel/filter-and-pagination-1

and

https://laracasts.com/discuss/channels/laravel/laravel-5-query-builder-search-filter

On the example here https://laracasts.com/discuss/channels/laravel/filter-and-pagination-1

If NOT using query string, you "build" parameters in your uri and pass as route parameters.

Jeffrey has video lessons, and there's documentation.

This "basic" passing parameters and query string usage should be mastered before delving deep into laravel.

Since crud is the main usage of a php framework, or a web database application.

Building search filters has also been discussed in depth.

If not paginating, just one post will work. If pagination the first search is "posted", thereafter "get" is used.

If you only knew how many times a search, query string, passing parameters, etc has been discussed here in the past.

I even posted a guide to help people find prior good laravel answers: But I will put it here again:

Go to google, in search type:

site:laracasts.com your search

//as example

site:laracasts.com build search filter  

 // or

site:laracasts.com dependent dropdown

Don't just search what I gave as example, put in some of your own search terms.

I can tell you that car drop downs for a car search has been discussed before.

Please or to participate in this conversation.