2014-04-07 101 views
0

我在Laravel 4應用程序中創建搜索功能。
Laravel 4多個搜索字段

它運作良好,事實上,它運作良好,唯一的事情,當我在我的郵政編碼字段搜索例如,然後單擊搜索。

我希望我搜索的值保留在文本輸入中。完全像設置值爲標準PHP/HTML中的PHP變量。

我已經包含了我的控制器功能和一個文本輸入框,以供您在下面看到。任何幫助將不勝感激,謝謝。

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')); 
} 



{{表格::文本( 'search_order_postcode',null,數組( '類'=> '形式控制', '佔位符'=> '訂單郵編'))}}

回答

1

您可以將search_order_postcode傳遞給您的視圖。

$this->layout->content = View::make('orders.index', compact('orders', 'search_order_postcode'), compact('perms')); 

在索引視圖或者其它任何創建初始搜索表單視圖中添加這個,所以你不要,如果不存在,它得到一個錯誤。
編輯:同時將它傳遞給你的搜索視圖從你的控制器。

$search_order_postcode = (isset($search_order_postcode) && $search_order_postcode !== '') ? $search_order_postcode : null; 

然後在您的視圖:

// 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')) }} 

沖洗重複用於其他投入,或者將其存儲在一個數組,所以你不臃腫你的看法::做,但是這是個人喜好。

+1

天才!,感謝您的快速回應:) – DommT