我想通过修补程序创建用户,并将值1分配给默认为0的布尔字段。 但它始终保存默认值0而不是将值设置为1.
这是我尝试过的(所有其他字段都获得了正确的值):
App\User::create(['email' => 'mail@mail.net','password' =>
bcrypt('password'),'is_admin' => 1])
... 'is_admin' => '1'
... 'is_admin' => true
... 'is_admin' => 'true'
这是我的迁移:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->boolean('is_admin')->default(false);
});
答案 0 :(得分:1)
尝试:
App\User::create(['email' => 'mail@mail.net','password' =>bcrypt('password'),
'is_admin' => boolval(1)]);
并验证模型中is_admin
是否为$fillable
;
protected $fillable = ['email','password','is_admin'];
只有可填写的属性