Laravel-admin: 表单字段default值报错

Created on 21 Dec 2017  ·  2Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.5
  • PHP Version:7.1
  • Laravel-admin: 1.5.7

Description:

表单字段问题。
这是我表单中的一个字段,设置了默认值:

$form->text('mobile', '手机')->default('');

对应的mysql字段的数字类型是这样的:

  mobile VARCHAR(255) DEFAULT '' NOT NULL COMMENT '手机',

当提交表单时,会报以下错误:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'mobile' cannot be null (SQL: update `team` set `position` = dede, `mobile` = , `updated_at` = 2017-12-21 13:18:23 where `id` = 1)

这个字段我已经设置了default值了,为啥还是会报错??

Steps To Reproduce:

Most helpful comment

app/Http/Kernel.php 里面有个中间件ConvertEmptyStringsToNull 会把request中所有的空字符串转换成null,要么去掉这个中间件,要么修改数据库

All 2 comments

源码是不是用了 ==null,而不是 ===null 做判断了?

app/Http/Kernel.php 里面有个中间件ConvertEmptyStringsToNull 会把request中所有的空字符串转换成null,要么去掉这个中间件,要么修改数据库

Was this page helpful?
0 / 5 - 0 ratings

Related issues

evans-kim picture evans-kim  ·  3Comments

taimaiduc picture taimaiduc  ·  3Comments

MarKco picture MarKco  ·  3Comments

joernroeder picture joernroeder  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments