Laravel:布尔字段

时间:2017-06-27 21:04:27

标签: php laravel laravel-5.4

我的一个表字段是布尔值:

$table->boolean('correio')->default(0);

这是标记:

<label>
    <input type="checkbox" name="correio" value="1"> Receber newsletter pelo correio?
</label>

在控制器上:

Associado::create(request(['matricula', 'correio']));

但是Laravel回复了这个错误:

  

完整性约束违规:1048栏&#39; correio&#39;不能为空

1 个答案:

答案 0 :(得分:1)

如果在桌面上添加一个隐藏字段感觉有点脏,我会在模型中亲自设置默认值,其中包含以下内容:

protected $correio = false;

OR

protected $correio = "0"; //Quoted as laravel/eloquent *may* turn 0's(ints) to null

OR

你可以让列可以为空吗?

相关问题