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

smacy's avatar
Level 1

get url paramer value in input field

my url is http://blog.test/category?filter[search]=asas i tried <input type="text" name="search" value="{{request()->get('filter[search]')}}" > i want to get asas as value in input field

0 likes
7 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@anilk sure. It was just to clean your code

<input type="text" name="search" value="{{request()->get('filter')['search'] ?? '' }}" > 
smacy's avatar
Level 1

@Sinnbeck one more question sir ...

for for the product search i have form like below.... i want to get selected for the options when select value matches in url like

http://gweb.test/jobs?filter[name]=kansas
http://gweb.test/services?filter[name]=kansas
http://gweb.test/accommodation?filter[name]=kansas
http://gweb.test/motor-vehicles?filter[name]=kansas
http://gweb.test/real-estate?filter[name]=kansas

i want to have options selected while visiting above url my form is

 <form action="{{ route('product.search') }}" method="GET">
                    <div class="input-group border-0">
                        <div class="input-group-text p-0">
                            <select class="form-select d-none d-xl-block" name="type" aria-label="Default select example">
                                <option value="market" @if (request()->has('market')) selected @endif>Market</option>
                                <option value="services" @if (request()->has('services')) selected @endif>Services</option>
                                <option value="jobs" @if (request()->has('jobs') && request()->get('jobs')==null) selected @endif>Jobs</option>

                                <option value="motor-vehicles" @if (request()->has('motor-vehicles')) selected @endif>Motor & Vehicles</option>
                                <option value="real-estate" @if (request()->has('real-estate')) selected @endif>Real Estate</option>
                                <option value="accommodations" @if (request()->has('accommodations')) selected @endif>Accommodations</option>
                            </select>
                        </div>

                        <input type="text" name="search" value="{{request()->get('filter')['search'] ?? '' }}" class="form-control" id="search_value" placeholder="Enter your search key ... ">
                        <div class="input-group-text p-0">
                            <button class="btn-search btn btn-hover-primary" type="submit">
                                Search
                            </button>
                        </div>
                    </div>
                </form>
Sinnbeck's avatar

@smacy that's why you need to move it to the controller.. Then it's just a single variable you are working with

Please or to participate in this conversation.