Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中下拉选择表单_Php_Laravel - Fatal编程技术网

Php 在Laravel中下拉选择表单

Php 在Laravel中下拉选择表单,php,laravel,Php,Laravel,我可以知道我的密码有什么问题吗?我在数据库中注册了三个用户类型名称,但是我的代码将生成三个下拉菜单,每个菜单上都有单独的用户类型名称 @foreach($user_types as $usertype) <div class="form-group"> {!! Form::select('chap_user_type_name', array('chap_user_name' => $usertype), null, ['class' => 'f

我可以知道我的密码有什么问题吗?我在数据库中注册了三个用户类型名称,但是我的代码将生成三个下拉菜单,每个菜单上都有单独的用户类型名称

@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($user\u类型为$usertype)
{!!Form::select('chap\u user\u type\u name',array('chap\u user\u name'=>$usertype')),null,['class'=>'Form control'])
@endforeach

删除foreach并像下面这样将数组传递给select

 {!! Form::select('chap_user_type_name',  $user_types, null, ['class' => 'form-control']) !!}

您不需要foreach上面的表单::select将处理它

如果
$user\u types
是一个集合,您需要使用
pulk()
构建正确的数组::select

$user_types = UserTypes::pluck('name', 'id');
然后只需像这样构建select元素:

{!! Form::select('chap_user_type_name', $usertype, null, ['class' => 'form-control']) !!}

非常感谢。它确实奏效了。。但是,它返回整个语句,例如:chap\u user\u type\u name;管理创建于;2016-08-27 04:13:28;更新(网址:;2016-09-06 08:38:43好的,当您在控制器中创建$user_类型时,仅从表中选择名称。。它将完成其余的工作..或者使用类似于$user\u types=\App\YourModel::lists('name','id')的lists方法;更改此$user_types=Chap_user_type::lists('name');好的,非常感谢。我现在明白了。。感谢您的回答:)在你们的帮助下,它现在开始工作了谢谢你的回答。。我会注意到这一点。。。谢谢!我该怎么做才能让这两个答案都被接受。。你们俩确实帮了我的忙:(@WhitneyW.,保持原样,别担心。将来你应该接受最高质量的答案,其中通常有正确的代码,并描述代码是如何工作的。如果几乎没有类似的答案,你应该选择最早的答案。这就是工作原理。