使用 Laravel Collective 选择输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52257994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:02:22  来源:igfitidea点击:

Select input with Laravel Collective

phplaravel

提问by Chukwuemeka Inya

{!! Form::select('country',['1' => 'Albania','2'=>'Kosovo','3'=>'Germany','4'=>'France'],null, ['class'=>'form-control','placeholder'=>'Select Country']) !!}

This type of input doesn't take the values of the array but instead, it takes the pre-default value of option inside select.enter code here

这种类型的输入不采用数组的值,而是采用 select.enter code here 中选项的预默认值

回答by Chukwuemeka Inya

According to the Form Collective documentation, the first argument of the Form::select()is the nameof the selectbox, the second is an arrayof the inputvalues while the third is the defaultvalue (this could be set to null). The fourth is an optional array of attributes/values.
This should work for you.

根据形式的集体文档,的第一个参数Form::select()name所述的select盒,第二个是array所述的input值,而第三个是default值(这可以被设置成null)。第四个是可选的属性/值数组。
这应该对你有用。

{!! Form::select('country',['Albania' => 'Albania','Kosovo'=>'Kosovo','Germany'=>'Germany','France'=>'France'],'Kosovo',['class'=>'form-control','placeholder'=>'Select Country']) !!}

回答by Leena Patel

{!! Form::select('country', [null => 'Select Country'] + ['Albania' => 'Albania','Kosovo'=>'Kosovo','Germany'=>'Germany','France'=>'France'], null, ['class' => 'form-control']) !!}

For more information : https://laravel.com/docs/4.2/html#drop-down-lists

欲了解更多信息:https: //laravel.com/docs/4.2/html#drop-down-lists