$this->crud->addField([
'name' => 'status',
'label' => 'Featured item',
'type' => 'checkbox',
]);
生成的代码如下:
<div class="form-group col-md-12">
<div class="checkbox">
<label>
<input type="hidden" value="0" name="status">
<input type="checkbox" name="status" value="1"> Featured item
</label>
</div>
</div>
使用上面的代码作为复选框,一切正常,值正确保存在数据库中并正确提取。但是未选中复选框。
对我来说,我的问题是在迁移更改了我的某些列之后,我的模型类中的$fillable
数组没有更新。
我记得要向XyzCrudController添加新字段,而不要向$fillable
数组添加新字段。