首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 4多重搜索字段

Laravel 4多重搜索字段
EN

Stack Overflow用户
提问于 2014-04-07 08:30:05
回答 1查看 1.6K关注 0票数 0

我在我的Laravel 4应用程序中创建了一个搜索功能。

它工作得很好,因为它运行良好,这是我在邮政编码字段中搜索并单击search的唯一方法。

我希望搜索的值保留在文本输入中。就像将值设置为标准PHP/HTML中的php变量一样。

我已经包含了我的控制器功能和文本输入字段,供您在下面查看。任何帮助都将不胜感激,谢谢。

代码语言:javascript
复制
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'));
}
代码语言:javascript
复制
 {{ Form::text('search\_order\_postcode', null, array('class'=>'form-control', 'placeholder'=>'Order Postcode')) }}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-07 08:53:08

您可以将search_order_postcode传递到视图。

代码语言:javascript
复制
$this->layout->content = View::make('orders.index', compact('orders', 'search_order_postcode'), compact('perms'));

将其添加到索引视图或任何创建初始搜索表单视图的地方,这样如果不存在,就不会得到错误。

编辑:也从你的控制器把它传递给你的搜索视图。

代码语言:javascript
复制
$search_order_postcode = (isset($search_order_postcode) && $search_order_postcode !== '') ? $search_order_postcode : null;

那么在你看来:

代码语言:javascript
复制
// 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,但这是个人偏好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22907255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档