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
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题