Laravel 中带有表单基础包的动态选择列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13493472/
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
Dynamic select list in Laravel with Form base bundle
提问by user1740151
Hi all i've been search for a while and can't find it in their documentation. does anyone know how to build a dynamic select list in laravel using the form-base plugin?
大家好,我已经搜索了一段时间,但在他们的文档中找不到它。有谁知道如何使用基于表单的插件在 Laravel 中构建动态选择列表?
Thanks
谢谢
回答by Shawn McCool
public function user_options()
{
return array('' => 'Choose a User') + User::lists('id', 'name');
}
{{ Form::select('user_id', UserWhateverForm::user_options(), UserWhateverForm::old('user_id')) }}
回答by aebersold
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');
In the array you can dynamicly specify the options/value. The last option is the default value.
在数组中,您可以动态指定选项/值。最后一个选项是默认值。
See the documentation.
请参阅文档。