Php &引用;一般错误:1366不正确的整数值“;即使我已将验证设置为nullable
我得到这个错误: 当我尝试创建时,我没有填写固定数量的输入 这是我在控制器中的存储(我已将fixed_quantity设置为nullable,所以应该可以了吧?) 这是我刀片上的内容:Php &引用;一般错误:1366不正确的整数值“;即使我已将验证设置为nullable,php,laravel-5,Php,Laravel 5,我得到这个错误: 当我尝试创建时,我没有填写固定数量的输入 这是我在控制器中的存储(我已将fixed_quantity设置为nullable,所以应该可以了吧?) 这是我刀片上的内容: <div class="form-group"> <label for="fixed_quantity">Quantity</label> <input class="form-control" type="number" id="fixed_quant
<div class="form-group">
<label for="fixed_quantity">Quantity</label>
<input class="form-control" type="number" id="fixed_quantity" name="fixed_quantity" value="{{ old('fixed_quantity') }}"" placeholder="0">
</div>
量
试试这个
插入前检查固定数量
'fixed_quantity' => $request->has('fixed_quantity') ? $request->input('fixed_quantity') : NULL,
这可为空
在整型字段上存储为字符串
这就是原因
'fixed_quantity' => 'nullable',
试试这个
插入前检查固定数量
'fixed_quantity' => $request->has('fixed_quantity') ? $request->input('fixed_quantity') : NULL,
这可为空
在整型字段上存储为字符串
这就是原因
'fixed_quantity' => 'nullable',
如果仔细观察,错误是它试图将'
放在列中
检查输入是否为空,如果为空则不要设置
if (!empty($request->input('fixed_quantity')))
$subscription_plan->fixed_quantity = $request->input('fixed_quantity');
如果仔细观察,错误是它试图将'
放在列中
检查输入是否为空,如果为空则不要设置
if (!empty($request->input('fixed_quantity')))
$subscription_plan->fixed_quantity = $request->input('fixed_quantity');
nullable
意味着null
是一个可接受的值,但您传递给它的是一个空字符串('
),而不是。将代码更改为以下内容:
$subscription_plan->fixed_quantity = !empty($request->input('fixed_quantity')) ? $request->input('fixed_quantity') : null;
nullable
意味着null
是一个可接受的值,但您传递给它的是一个空字符串('
),而不是。将代码更改为以下内容:
$subscription_plan->fixed_quantity = !empty($request->input('fixed_quantity')) ? $request->input('fixed_quantity') : null;
存储的是什么值?你能查一下吗?因为如果输入是数字且为空,我认为Laravel会尝试将其设置为空字符串。@Phiter由于未保存到数据库,因此错误中仅为“”。存储了什么值?你能查一下吗?因为如果输入是数字且为空,我认为Laravel会尝试将其设置为空字符串。@Phiter因为它没有保存到数据库,所以在错误中它只是''。顺便说一句,Laravel有一个ConvertEmptyStringsToull
中间件,它完全按照名称对每个请求参数执行。顺便说一下,Laravel有一个ConvertEmptyStringsToull
中间件,它完全按照每个请求参数的名称执行。