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,
so instead of the town selected item gets reseted back to the first item in the dropdown menu, we can now presist through the url query-string without to much work.

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