我已经在$fillable中加了images字段,但是create的时候老是保存不进去
模型
protected $fillable = [
'user_id', 'type', 'content', 'images'
];
插入
$dynamic = Dynamic::create([
'user_id' => auth('api')->id(),
'content' => request()->post('content', ''),
'images' => implode(',', $images)
]);
//=== 下面这种方式也不行 ===
$dynamic = Dynamic::create([
'user_id' => auth('api')->id(),
'content' => request()->post('content', ''),
'images' => '1111111111111', //implode(',', $images)
]);
报错
#sql: "insert into `dynamics` (`user_id`, `content`, `updated_at`, `created_at`) values (?, ?, ?, ?)"
#bindings: array:4 [
0 => 100000
1 => ""
2 => "2020-08-07 09:41:32"
3 => "2020-08-07 09:41:32"
]
#message: "SQLSTATE[HY000]: General error: 1364 Field 'images' doesn't have a default value (SQL: insert into `dynamics` (`user_id`, `content`, `updated_at`, `created_at`) values (100000, , 2020-08-07 09:41:32, 2020-08-07 09:41:32))"
我又加了一个images2字段,就可以保存,images是laravel的关键词吗????
推荐文章: