[英]Form::model binding Laravel with <select multiple>
I just discorvered that Form::model
binding existed and I'm delighted with (it's wonderful). 我刚刚发现
Form::model
绑定存在,我很高兴(很棒)。 I tried it with text, email, and even select, every single time it worked. 我每次使用文本,电子邮件,甚至选择它都会尝试它。
My question is, will it work with a <select multiple>
? 我的问题是,它会与
<select multiple>
吗? If it does, how am I supposed to use it and what is the correct way to save an array in the database? 如果是这样,我该如何使用它以及在数据库中保存数组的正确方法是什么? (This may be awful but I concatenate all the options of the array with a separator and save it as text, I'm sure it's not the correct way to do it).
(这可能很糟糕,但我将数组的所有选项与分隔符连接起来并将其保存为文本,我确定这不是正确的方法)。
just like this : 像这样 :
Form::select('menus[]', $menus, null, array(
'multiple' => true,
'class' => 'form-control'
));
take a note : 记录一下 :
param 1 : should be your field name (if want multiple add array tag aftrer field name eg : menus[]
) param 1:应该是你的字段名称(如果想要多个add array tag aftrer字段名称,例如:
menus[]
)
param 2 : list menu (array) eg : array('value1' => 'text1', 'value2' => 'text2')
param 2:list menu(array)eg:
array('value1' => 'text1', 'value2' => 'text2')
param 3 : selected values. 参数3:选定的值。 (should be
null
because Form::model
will perform automatically matching values from database. and make sure the field name has same with key
data result from database ) (应为
null
因为Form::model
将自动匹配数据库中的值。 并确保字段名称与数据库中的key
数据结果相同 )
param 4 : is property for element <select>
you can add class, id, and etc.. param 4:是元素
<select>
属性,你可以添加class,id等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.