dongqieli4164 2016-08-10 05:24
浏览 74
已采纳

如何从laravel 5.2中的数据库中获取值到过滤器搜索的下拉列表

I am doing project in laravel 5.2, for report creation in "vehicleDetail.blade.php" i need to give one drop down option, in that i need to get vehicle names which are there in the database. From that list if i select one vehicle, select fromDate , toDate and then click on generate report i should be able to fetch data from the database (device table). For this filter engine how can i make the drop down list byb fetching data fro the database?

vehicleDetail.blade.php

 @extends('app')

@section('content')
    <br><br><br><br><br>
    <div class="templatemo-content-wrapper">
        <div class="container">
            <ol class="breadcrumb">
                <li><a href="{{ url("/") }}"><font color="green">Home</font></a></li>
                <li class="active">Vehicle Detail</li>
            </ol>
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <div class="panel panel-success">
                        <div class="panel-heading">Vehicle Detail</div>
                        <div class="panel-body">
                            @if (count($errors) > 0)
                                <div class="alert alert-danger">
                                    <strong>Whoops!</strong> There were some problems with your input.<br><br>
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif

                            <form class="form-horizontal" role="form" method="POST" action="{{ url('group/update/') }}">
                                <input type="hidden" name="_token" value="{{ csrf_token() }}">

                                    <div class="form-group">
                                        <label class="col-md-4 control-label">Vehicle</label>
                                        <div class="col-md-6">

                                            <input type="text" class="form-control" name="groupID" value="{{ ('#')}}">

                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-2 control-label">From Date</label>
                                        <div class="col-md-6">
                                            <input type="date" class="form-control" name="Fdate">
                                        </div>

                                        <label class="col-md-4 control-label">To Date</label>
                                        <div class="col-md-6">
                                            <input type="date" class="form-control" name="Tdate" >
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-4">
                                            <button type="submit" class="btn btn-warning">
                                                Get Report
                                            </button>
                                        </div>
                                    </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Any one please help me to do this, response are appreciable.

  • 写回答

1条回答 默认 最新

  • duanbodai5166 2016-08-10 05:37
    关注

    In your controller get all values from database in a variable like:

    $list = DB::table('tablename')->get(array('id', 'name'));
    

    and pass it on view like:

    return view('viewname', array('list' => $list));
    

    Now use it on view like:

    foreach($list as $key => $val)
    {
        //drop down html here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?