使用来自 Laravel Blade 数据库的数据填充单选按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27478723/
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 10:33:21  来源:igfitidea点击:

Fill radio button with data coming from database Laravel Blade

phpformslaravelradio-buttonblade

提问by jake balba

So I am now working with the update part of my program, now i want to populate my forms with the older records from my database to edit it. Now my problem is the radio button, how can select the true one. I tried this code, i use if on my radio buttons

所以我现在正在处理我程序的更新部分,现在我想用我的数据库中的旧记录填充我的表单以对其进行编辑。现在我的问题是单选按钮,如何才能选择真正的按钮。我试过这个代码,我在我的单选按钮上使用 if

    {{ Form::label('Type','Type')}}    
    {{ Form::radio('ctype', '1',if(($item->bname)==1){true}) }}
    {{ Form::label('Rooster','Rooster')}}    
    {{ Form::radio('ctype', '0') }}
    {{ Form::label('Hen','Hen')}}    

But I just get error 500, please help

但我只是收到错误 500,请帮忙

回答by MaGnetas

In the documentation it says:

在文档中它说:

echo Form::radio('name', 'value', true);

So you should go this way:

所以你应该这样走:

{{ Form::radio('ctype', '1', $item->bname == 1) }}

You shouldn't need any additional brackets. Third param is a simple boolean value.

您不应该需要任何额外的括号。第三个参数是一个简单的布尔值。