php - Laravel 中的单选按钮始终采用 bool 值 0

标签 php database html laravel-5 radio-button

我创建了单选按钮字段,如下所示

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

<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。另外,我可以选择多个单选按钮,这不应该发生。 我做错了什么吗?

最佳答案

您应该进行以下更改,然后您的 Controller 查询将按照您的要求工作!

    <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>

关于php - Laravel 中的单选按钮始终采用 bool 值 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34289628/

相关文章:

PHP 认为 null 等于零

php - 是否有用于 PHP 的 'best' Google 图表 API?

php - MySQL创建的线程快速增长

java - 从选项卡表单链接回选项卡面板

javascript - 使 onclick 只影响该元素,而不影响它的子元素

javascript - 如何实现循环以使我的程序不会崩溃?

php - 在 laravel 中选择具有最大计数的项目

php - sql UPDATE,一个计算被多次使用,是否可以只计算一次?

java - ODatabaseException : Database instance is not set in current thread while dropping database

sql - 动态创建表作为分区的一种方式 : OK or bad practice?