无法将类添加到 Laravel 表单选择

Posted

技术标签:

【中文标题】无法将类添加到 Laravel 表单选择【英文标题】:Unble to add a class to Laravel form select 【发布时间】:2020-06-14 12:34:00 【问题描述】:

我正在使用 Laravel 表单。这是我的代码。

<?php
      $options = $items->pluck('name', 'id')->toArray();
      $options[''] = "Choose...";
?>

!! Form::select('item_id', $options, array('class' => 'form-control')) !!
@error('item_id')
     <div class="alert alert-danger"> $message </div>
@enderror

可惜浏览器不渲染css类,

<select name="item_id">
   ....
</select>

【问题讨论】:

【参考方案1】:

表单的第三个参数是选择的选项,因此您需要将带有类的数组作为第四个参数传递。例如:

!! Form::select('item_id', $options, null, array('class' => 'form-control')) !!

【讨论】:

以上是关于无法将类添加到 Laravel 表单选择的主要内容,如果未能解决你的问题,请参考以下文章