[英]How to make a form with multiple items from database with laravel
I have taken a list of items from a table in my DB , now I want to make a form that consists of a dropdown box containing all these items. 我已经从数据库的一个表中获取了项目列表,现在我想制作一个包含所有这些项目的下拉框的表单。 And when I click an item I want it to be added to a list next to the listbox so I can save these multiple items in my db .
当我单击一个项目时,我希望将其添加到列表框旁边的列表中,以便将这些多个项目保存在我的数据库中。 (The main goal is to select a single or multiple labels for a newsitem in my site)
(主要目标是为我的网站中的一个新站点选择一个或多个标签)
code in html that gives list of labels (working) : html中的代码(提供标签列表)(工作):
@foreach($labels as $label)
<p>{{$label}}</p>
@endforeach
Now I need a {{Form:: ...... element that creates a dropdown box of all these labels. 现在,我需要一个{{Form :: ......元素,该元素会创建一个包含所有这些标签的下拉框。
I solved this with a jquery plugin : 我用一个jQuery插件解决了这个问题:
http://harvesthq.github.io/chosen/ http://harvesthq.github.io/chosen/
and this code : 和此代码:
<div class="form-group">
<select name="labels[]" class="form-control chosen-select-video" data-placeholder="Add labels..." multiple >
@foreach ($labels as $title)
<option value="{{$title}}">{{ucfirst($title)}}</option> <!-- Capitalize first letter -->
@endforeach
</select>
</div>
To create a dropdown list in laravel you can use- 要在laravel中创建下拉列表,您可以使用-
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
here array
is your list taken from database. 这里的
array
是您从数据库中获取的列表。 you can find details about laravel form helper in this link . 您可以在此链接中找到有关laravel form helper的详细信息。 and for showing a list of selected item next to your dropdownlist you should use javascript or jQuery.
并且为了在下拉列表旁边显示所选项目的列表,您应该使用javascript或jQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.