【发布时间】:2021-05-22 13:04:45
【问题描述】:
这是一个通过批量作业分配加载的示例代码:
someModel::create([
'test' => $data->test
]);
在“someModel”中,我有以下突变体:
public function setTestAttribute($value)
{
$this->attributes['test'] = '1234'; //Hash::make($value) instead of 1234 is not working either
}
当我运行代码时,db 中“test”列的内容不是 1234,而是来自 $data 变量的数据。所以mutator没有操纵数据。我在这里缺少一些基本的东西吗?
我尝试在 setTestAttribute 中执行 dd('test'),它显示得很完美,所以它正在初始化,只是没有设置/覆盖值。
db中的“Test”列类型为:varchar,模型设置中可以填写test。
【问题讨论】:
-
也许你会展示更多你的代码