我有大型单个MongoDB集合,我想为每个字段添加时间戳。我这样做:
$automation = Automation::all();
foreach ($automation as $workflowindex => $workflow)
{
foreach ($workflow['workflow'] as $itemindex => $items)
{
foreach ($items['subscribers'] as $index => $item)
{
foreach ($items as $name => $mail)
{
if ($name != 'subscribers') {
if ($mail['delay'] == "0" && $mail['delay_time'] == 'now') {
$automation[$workflowindex]['workflow'][$itemindex]['subscribers'][$index][$name] = round(time()/60)*60;
$automation->save();
}
}
}
}
}
}
但是,如果我尝试保存此集合,则会收到错误消息
间接修改App \ Automation的重载元素无效
如果我使用方法
Automation::all()->toArray();
我仍然无法保存,因为save方法对数组不起作用。在foreach循环中访问该字段有更好的选择吗?如果不是,那我该怎么保存这个集合呢?