1

I have large, single MongoDB collections and I want to add a timestamp to each of its fields. I do it that way:

$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();
                    }
                }
            }

        }
    }
}

However, if I try to save this collection I get an error saying

Indirect modification of overloaded element of App\Automation has no effect

If I use the method

Automation::all()->toArray();

I still cannot save, beause the save method doesn't work on arrays. Is there a better option to access the field in my foreach loops? If no, then how can I save this collection?

0 Answers0