如何从复选框中的表中读取数据

时间:2019-06-19 19:44:42

标签: php html mysql laravel

我有一个表(rs_insure),其中的列名为“ id_cover”,其int值如1(true),0(false),并且我想在我的视图中列出它们并带有一个复选框,如果需要,请选中该复选框是true,如果为false,则未标记,显然是只读的。

这就是我试图做到的方式

<tbody>
    @foreach ($rs_insure as $insure)
        <tr>
            <td class="text-center"> {{ $insure->id_employee}}   </td>
            <td class="text-center">{{ $insure->charge }}</td>
            <td class="text-center">{{ $insure->desc}}</td>
            <td class="text-center">{{$insure->application_date}}</td>            
            <td class="text-center">
                <input type="checkbox" disabled="true" value=""/>
                {{ $insure->id_cover}}
            </td>
        </tr>
    @endforeach
</tbody>

2 个答案:

答案 0 :(得分:1)

夫妇,

  1. 如果input被禁用,则如果它是表单的一部分,它将不提交,如果您的意图是使用readonly属性,否则并不重要。
  2. 检查对象的属性是否为真,并使用内联if只需添加选中的属性或不添加任何内容。

<input type="checkbox" readonly {{ $insure->id_cover ? 'checked' : '' }} />

答案 1 :(得分:0)

您可以使用条件将其标记为已选中:

<input type="checkbox" disabled="true" value="" @if($insure->id_cover) checked @endif/>