/** * Execute the console command. * * @return mixed */ public function handle() { AssignmentUpdate::all()->each(function ($update) { $update->created_at = $update->created_at_old; $update->updated_at = $update->updated_at_old; $update->save(); }); }
/** * Execute the console command. * * @return mixed */ public function handle() { $updatesGroupByAssignment = AssignmentUpdate::all()->groupBy('assignment_id'); $updatesGroupByAssignment->each(function ($group) { // dd($group); $orderedUpdates = $group->sortBy('created_at'); while ($orderedUpdates->count() > 0) { $currentUpdate = $orderedUpdates->pop(); $previousUpdate = $orderedUpdates->last(); if ($previousUpdate) { $currentUpdate->previous_assignment_id = $previousUpdate->id; $currentUpdate->save(); } } }); }