Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php firstOrCreate未添加属性,因此无法创建模型_Php_Laravel - Fatal编程技术网

Php firstOrCreate未添加属性,因此无法创建模型

Php firstOrCreate未添加属性,因此无法创建模型,php,laravel,Php,Laravel,我有一个常用的用户模型表 Id | name | email | nullable column | password | nullable column | timestamps | ROLE 使用first或create或first或new $user = User::firstOrNew([ 'email' => $user->email ], [ 'name' => $user->name,

我有一个常用的用户模型表

Id | name | email | nullable column | password | nullable column | timestamps | ROLE
使用
first或create
first或new

$user = User::firstOrNew([
            'email' => $user->email
        ], [
            'name' =>  $user->name,
            'password' => Hash::make(Str::random(24)),
            'role' => 0
        ]);
获取此消息时出现一般错误:1364字段“角色”没有默认值

这让我觉得很奇怪,因为我正在传递带有属性的
角色


发现如果我只通过了
first或create
$user->role
,然后通过了
$user->save
,我成功了,但我不确定这种解决方法是否会在将来给我带来麻烦。?我没有用此修复程序覆盖现有用户角色吗?我更愿意简单地使用
first或create

您是否在您的用户模型中将
role
添加到$filleble变量?在用户模型中将
role
添加到
$filleble
解决了
first或create
问题。谢谢@HenryBui。真正的原因是大规模作业,你可以在这里阅读更多