How To Retrieve Old Data Within The View() Instead Of Redirect() In Laravel (v5.*)

** lets say you have a dropdown menu where you select the city, town & you want to get all the products under this town,
but now when you submit the search form, one of dropdown menu “in our case, the towns menu” could lose its selection & reset back to the first item,
however we could leverage the url query-string to fix this issue and persist the selection.

1- in your search controller

$search_result = // your query ;

return view('the.view',compact('search_result'));

2- in the search view


{{ Form::select(
  $something->lists('name', 'id'),
  $request->town_id // this is how we get the current query

{{-- $search_result --}}

now the dropdown will select the option that is equal to the query in the url, if not it will be null.

if u have dynamic dropdown, use the above in conjunction with Dynamic Dropdown With Form Data Binding Laravel


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.