[英]Laravel 5.2 - Passing a value and text to select box
In my controller I am passing a multiple array to the view. 在我的控制器中,我将多个数组传递给视图。 The arrays that I am passing look like this: 我传递的数组如下所示:
$charts['names'] = ['Artikler lest', 'Antall kommentarer', 'Antall "bli med"', 'Tid på døgnet'];
$charts['values'] = ['Article', 'Comment', 'Thumb', 'View'];
return view('admin.charts.show',
compact(
'charts',
)
);
}
And in my view I have a select box that looks like this: 在我看来,我有一个选择框,如下所示:
<div class="large-4 columns end">
{!! Form::select('velg', $charts['names'], null, ['id' => 'timelines']) !!}
</div>
With this I am passing just text to the select box, I would also like to pass a values so that they are connnected like this: 通过此操作,我仅将文本传递到选择框,我还想传递一个值,以便像这样连接它们:
<option value="Article">Artikler lest</option>
<option value="Comment">Antall kommentarer</option>
<option value="Thumb">Antall "bli med"</option>
<option value="View">Tid på døgnet</option>
How would I do such thing with Laravel collective? 我如何与Laravel集体一起做这样的事情?
Just pass through an array with the keys as the option value: 只需将键作为选项值通过一个数组即可:
$charts = [
'Article' => 'Artikler lest',
'Comment' => 'Antall kommentarer',
'Thumb' => 'Antall "bli med"',
'View' => 'Tid på døgnet'
];
The form builder will use the key for the value of the option. 表单构建器将使用键作为选项的值。 https://laravelcollective.com/docs/5.2/html#drop-down-lists https://laravelcollective.com/docs/5.2/html#drop-down-lists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.