jbowman99's avatar

Return search with Search values

I have a search bar with multiple inputs, when the page returns the view with the search results, how can I pass back the inputs that were searched for so the Search Fields remain populated?

currently i'm returning a view:

return view('listings', compact('listings');

i tried withInput() then grabbing the {{ old['input'] }} didn't work.

how can i return the search results and the input?

0 likes
5 replies
EventFellows's avatar

Depending on how you are handling the search parameters you might want to use this:

$request->getQueryString()
jbowman99's avatar

@EventFellows

Controller method:

public function listings(Request $request)
    {
        $data = $request->all();

        $listings = Listing::all();

        if($data){
            $listings = (new SearchListings($request))->search();
        }

        return view('listings', compact('listings'))->with('data');
    }

jbowman99's avatar

@EventFellows

just a snippet:

<div class="form-group search-mls">
                    <label class="control-label" for="mlsnumber">MLS#</label>
                    <div>
                        <input id="mlsnumber" name="mlsnumber" placeholder="MLS#" class="form-control input-md" type="text" value="{{ $data ? $data['mlsnumber'] : "" }}">
                    </div>
                </div>

                <div class="form-group search-zip">
                    <label class="control-label" for="zipcode">Zip</label>
                    <div class="">
                        <input id="zipcode" name="zipcode" placeholder="Zip Code" class="form-control input-md" type="text" value="{{ $data ? $data['zipcode'] : "" }}">
                    </div>
                </div>

                <div class="form-group search-type">
                    <label class="control-label hidden-on-desktop" for="propertytype">Property Type</label>
                    <div class="">
                        <select id="propertytype" name="propertytype" class="form-control">
                            <option value="" selected="selected">Type</option>
                            <option value="Residential">Residential</option>
                            <option value="Townhouse">Townhouse / Condo</option>
                            <option value="Multi">Multi-Family</option>
                            <option value="Land">Land</option>
                            <option value="Commercial">Commercial / Business</option>
                        </select>
                    </div>
                </div>

the ternary operation for value is working for single inputs now. Stuck on the select boxes at the moment

AhimbisibweRoland's avatar

just use the request helper in your forms

something like this

<input type="search" name="field" value="{{request('field')}}"/>

For select boxes just use javascript or any front end related tool an example in javascript

document.getElementById("selectBoxId").value = "{{ old("selectBoxName") }}";
2 likes

Please or to participate in this conversation.