public function moveTo($destinationForum) { if ($this->forum_id === $destinationForum->forum_id) { return true; } if (!$this->forum->isOpen()) { return false; } return DB::transaction(function () use($destinationForum) { $originForum = $this->forum; $this->forum()->associate($destinationForum); $this->save(); $this->posts()->update(['forum_id' => $destinationForum->forum_id]); $this->logs()->update(['forum_id' => $destinationForum->forum_id]); $this->userTracks()->update(['forum_id' => $destinationForum->forum_id]); if ($originForum !== null) { $originForum->refreshCache(); } if ($this->forum !== null) { $this->forum->refreshCache(); } $users = User::whereIn('user_id', model_pluck($this->posts(), 'poster_id'))->get(); foreach ($users as $user) { $user->refreshForumCache(); } Log::logModerateForumTopicMove($this, $originForum); return true; }); }