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 querie ;

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

2- in the search view

@inject('request','Illuminate\Http\Request')

{{ Form::select(
  'name',
  $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 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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s