无效的表单数据是返回值的“ 0”。在数据库中
我正在尝试将一个空输入字段存储到我的数据库中,并希望将其存储为“ null”,但是,如果我在提交表单时将输入字段留为空,则将其存储为“ 0”在我的数据库中。
在我的控制器中,我有以下内容:
$campaignRules = [
'lines_available' => 'nullable|numeric',
];
以我的形式,我有:
<div class="col-xl-12 input-container">
<label for="" class="f-14 text-grey label">
Lines Available (optional)
</label>
<input name="lines_available" type="number" class="custom-form" placeholder="Enter lines available...">
</div>
在我的数据库中,我将字段存储为整数,已检查“允许nullable”检查,并且将字段集的默认值设置为“ null”。我想不出任何其他原因,为什么将其存储为0,并将其设置为所有的东西。
有指导吗?再次感谢。
I'm trying to store an empty input field into my database and would like for it to be stored as "NULL", however, If I leave the input field empty when I go to submit my form, It is stored as "0" in my database.
In my controller, I have the following:
$campaignRules = [
'lines_available' => 'nullable|numeric',
];
In my form I have:
<div class="col-xl-12 input-container">
<label for="" class="f-14 text-grey label">
Lines Available (optional)
</label>
<input name="lines_available" type="number" class="custom-form" placeholder="Enter lines available...">
</div>
In my database, I have the field stored as an integer, have "Allow Nullable" checked and have the default value of the field set as "NULL". I can't think of any other reason as to why it would be stored as 0 with all the things I have set in place.
Any guidance? Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过执行以下操作修复了它:
这是在将条目保存在控制器中之前完成的。
I fixed it by doing the following:
This is done before the entry is saved within the controller.