【问题标题】:Laravel 4 Multiple Search FieldsLaravel 4 多个搜索字段
【发布时间】:2014-05-19 09:23:28
【问题描述】:

我正在我的 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'));
}



{{ Form::text('search_order_postcode', null, array('class'=>'form-control', 'placeholder'=>'Order Postcode')) }}

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案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')) }}
    

    冲洗其他输入的重复,或将它们存储在一个数组中,这样你就不会膨胀你的视图::make,但这是个人喜好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 1970-01-01
      • 2019-01-03
      • 2019-08-11
      • 2021-08-05
      • 2015-06-17
      相关资源
      最近更新 更多