简体   繁体   English

Laravel刀片-设置所选值(如果存在)

[英]Laravel blade - set selected value if exists

I have a form that can be used to submit and edit something. 我有一个可用于提交和编辑内容的表格。 There are a few dropdown menus for which I want to set the selected value if the form is in edit mode. 如果表单处于编辑模式,我想为几个下拉菜单设置选定的值。 If the variable $holder -> year exists, it must print its value. 如果变量$ holder-> year存在,则必须打印其值。 Otherwise an empty value should be selected. 否则,应选择一个空值。 I can't seem to fix this using the 'or' tag. 我似乎无法使用“或”标签解决此问题。

My code looks like this 我的代码看起来像这样

'2013' => '2013',
'2014' => '2014',
'2015' => '2015'
),$holder-> year,
array('class' => 'form-control', 'id' => 'year')
) }}

Thanks in advance 提前致谢

You should add an empty value to your options array, something like: 您应该在选项数组中添加一个空值,例如:

['' => '-- Select year --']

And I assume your year parameter is representing a column in databse, that means if the column is empty, it returns as empty and should select the option I mentioned. 我假设您的year参数表示数据库中的一列,这意味着如果该列为空,则返回为空,应选择我提到的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM