[英]Drop down select form in Laravel
may I know what is wrong with my codes? 我可以知道我的代码有什么问题吗? I have three user type name registered in my database however my codes will result to three drop down menus with individual user type name on each. 我在我的数据库中注册了三个用户类型名称,但是我的代码将生成三个下拉菜单,每个菜单上都有单独的用户类型名称。
@foreach($user_types as $usertype)
<div class="form-group">
{!! Form::select('chap_user_type_name', array('chap_user_name' => $usertype), null, ['class' => 'form-control']) !!}
</div>
@endforeach
删除foreach并将数组传递给像这样的选择
{!! Form::select('chap_user_type_name', $user_types, null, ['class' => 'form-control']) !!}
If $user_types
is a collection, you need to use pluck()
to build correct array for ::select
: 如果$user_types
是一个集合,则需要使用pluck()
为::select
构建正确的数组:
$user_types = UserTypes::pluck('name', 'id');
Then just build select element like this: 然后只需构建这样的select元素:
{!! Form::select('chap_user_type_name', $usertype, null, ['class' => 'form-control']) !!}
你不需要上面的foreach形式:: select会照顾它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.