Laravel Dropdown表格获取表格数据库

时间:2017-12-17 19:50:26

标签: php laravel

我正在使用laravel 5.4。我试图获取数据表格部门表和数据也有问题还有更多下拉菜单也请告诉我怎样才能解决这个问题。谢谢你。[

<div class="form-group">
                        {{Form::label('department','Department')}}
     @foreach($department as $value)
      {{Form::select('department',[$value->name], ' ', array('placeholder' => 'Select Department','class'=>'form-control'))}}
     @endforeach

 </div>

2 个答案:

答案 0 :(得分:1)

不完全清楚你追求的是什么。您当前的代码似乎输出了几个选择框,每个部门一个,我最好的猜测是您只想输出一个选择框,每个部门作为选项。您可以通过执行此类操作来实现此目的(您可能需要稍微调整此代码以满足您的需求):

手动方法

<div class="form-group">
    <label for="department">Department</label>
    <select id="department" name="department" class="form-control">
        <option value="">Select Department</option>
        @foreach ($departments as $department)
            <option value="{{ $department->id }}">{{ $department->name }}</option>
        @endforeach
    </select>
</div>

使用Laravel Collective的表单生成器

<div class="form-group">
    {!! Form::label('department', 'Department') !!}
    {!! Form::select('department', ['' => 'Select Department'] + $departments->pluck'name', 'id')) !!}
</div>

答案 1 :(得分:0)

尝试这样做: -

<div class="form-group">
  {{Form::label('department','Department')}}
  <select class="form-control" name="department">
    @foreach($department as $value)
      <option value="$value">$value</option>
    @endforeach
  </select>
</div>