Reputation: 155
I am creating a search function in my Laravel 4 Application.
It is working great, in the fact that it is functioning well, the only thing that when I search for example in my postcode field and click search.
I want the value that I search to stay in the text input. Exactly like setting the value to be a php variable in standard PHP/HTML.
I have included my controller function and a text input field for you to see below. Any help would be greatly appreciated, thanks.
public function postSearch()
{
$search_order_from_date = Input::get('search_order_from_date');
$search_order_to_date = Input::get('search_order_to_date');
$search_order_type = Input::get('search_order_type');
$search_order_status = Input::get('search_order_status');
$search_order_agent = Input::get('search_order_agent');
$search_order_assessor = Input::get('search_order_assessor');
$search_order_postcode = Input::get('search_order_postcode');
$orders = DB::table('orders')
// ->where('order_date', '>=', $search_order_from_date, 'and', 'order_date', '<=', $search_order_to_date, 'or')
->orWhere('type', '=', $search_order_type)
->orWhere('epc_status', '=', $search_order_status)
->orWhere('agent', '=', $search_order_agent)
->orWhere('assessor', '=', $search_order_assessor)
->orWhere('postcode', '=', $search_order_postcode)
->orderBy('order_date', 'DESC')
->paginate();
Session::put('search', 'search query');
$users = User::all();
$userType = Session::get('type');
$perms = DB::table('permissions')->where('user_type', $userType)->first();
$this->layout->content = View::make('orders.index', compact('orders'), compact('perms'));
}
{{ Form::text('search_order_postcode', null, array('class'=>'form-control', 'placeholder'=>'Order Postcode')) }}
Upvotes: 0
Views: 1659
Reputation: 1659
You can pass search_order_postcode to your view.
$this->layout->content = View::make('orders.index', compact('orders', 'search_order_postcode'), compact('perms'));
Add this in your index view or where ever the initial search form view is created, so you dont get an error if it does not exists.
Edit: Also pass it to your search view from you controller.
$search_order_postcode = (isset($search_order_postcode) && $search_order_postcode !== '') ? $search_order_postcode : null;
Then in your view:
// Search_order_postcode is either the value it was given or null
{{ Form::text('search_order_postcode', $search_order_postcode, array('class'=>'form-control', 'placeholder'=>'Order Postcode')) }}
Rinse repeat for other inputs, or store them in an array so you dont bloat your view::make, but this is personal preference.
Upvotes: 1