本文介绍了单选按钮总是在laravel中取boolean 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建如下的单选按钮字段

I have created radio button fields as follows

编辑:我已按照评论中的建议更改表单 b

<div class="form-group">
    {!! Form::label('is_kids_friendly','Kids Friendly:') !!}
    {!! Form::radio('kidsfriendly', 'true', null),'&nbsp', 'Yes' !!}
    {!! Form::radio('kidsfriendly', 'false', null),'&nbsp','No' !!}
</div>

<div class="form-group">
    {!! Form::label('is_kids_only','Kids Only:') !!}
    {!! Form::radio('kidsonly', 'true', null),'&nbsp', 'Yes' !!}
    {!! Form::radio('kidsonly', 'false', null),'&nbsp','No' !!}
</div>

<div class="form-group">
    {!! Form::label('sineor_citizan_friendly','Sineor Citizan Friendly:') !!}
    {!! Form::radio('seniorcitizen', 'true', null),'&nbsp', 'Yes' !!}
    {!! Form::radio('seniorcitizen', 'false', null),'&nbsp','No' !!}
</div>

由于这是单选按钮字段,我使用了 boolean 在数据库中。
每次,我填写详细信息,它需要 0 。此外,我可以选择多个单选按钮,这不应该发生。
我做错了什么?

As this is radio button field, i have used boolean in database.Each time, i fill in details, It takes 0. Also, i can select multiple radio button, thats should not happen.Am i doing something wrong?

推荐答案

您应该做以下更改,然后您的控制器查询将按照您的需要工作!

You should do following changes then your controller query will work as you want!

    <div class="form-group">
    {!! Form::label('is_kids_friendly','Kids Friendly:') !!}
    {!! Form::radio('is_kids_friendly', true, null),'&nbsp', 'Yes' !!}
    {!! Form::radio('is_kids_friendly', false, null),'&nbsp','No' !!}
</div>

<div class="form-group">
    {!! Form::label('is_kids_only','Kids Only:') !!}
    {!! Form::radio('is_kids_only', true, null),'&nbsp', 'Yes' !!}
    {!! Form::radio('is_kids_only', false, null),'&nbsp','No' !!}
</div>

<div class="form-group">
    {!! Form::label('sineor_citizan_friendly','Sineor Citizan Friendly:') !!}
    {!! Form::radio('sineor_citizan_friendly', true, null),'&nbsp', 'Yes' !!}
    {!! Form::radio('sineor_citizan_friendly', false, null),'&nbsp','No' !!}
</div>

这篇关于单选按钮总是在laravel中取boolean 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:14