如何在Laravel中的dropdwon中填充数据库值 [英] How to populate database values in dropdwon in laravel

查看:70
本文介绍了如何在Laravel中的dropdwon中填充数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在下拉列表中显示数据库值..我尝试了很多,但是对我来说不起作用. 我收到错误,我不知道我在哪里弄错了..我是laravel的新手..请帮助我我在哪里弄错了..

i want to show the database values in drop down..i tried a lot but it's not working for me.. i am getting errors i don't know where i mistaken..i am new to laravel..please help me where i mistaken..

视图:

<div class="form-group">
<label for="name" class="col-md-4 control-label">User type</label>

<div class="col-md-6">
        <?php
        {!!Form::select('user_type_id[]', $usertypes_list, $thing->user_type->pluck('id'), ['class' => 'form-control'])!!}
        ;?>
</div>

控制器:

public function get() {
    $usertypes_list = User_type::lists('id', 'type');
    return view('edit')->compact('user_type');
}

谁能帮我... 预先感谢.

Can anyone help me... Thanks in advance.

推荐答案

运行composer require "laravelcollective/html":"^5.4"laravelcollective添加到您的项目中,因为Form::select在laravel 5+中不再可用

run composer require "laravelcollective/html":"^5.4" to add laravelcollective to your project as Form::select is no longer available in laravel 5+

并快速浏览此laravelcollective文档

修改: 在您的控制器中,您必须传递$usertypes_list,因此该功能应为

in your controller you've to pass $usertypes_list so the function should be

public function get() {
    $usertypes_list = User_type::pluck('id', 'type');
    return view('edit')->compact('usertypes_list');
}

然后您的视图应如下所示:

then your view should looks like:

<div class="form-group">
<label for="name" class="col-md-4 control-label">User type</label>

<div class="col-md-6">
        {!!Form::select('user_type_id[]', $usertypes_list, null, ['class' => 'form-control'])!!}
</div>

这篇关于如何在Laravel中的dropdwon中填充数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆