public function addPost($poster, $body) { $post = new Post(['post_text' => $body, 'post_username' => $poster->username, 'poster_id' => $poster->user_id, 'forum_id' => $this->forum_id, 'post_time' => Carbon::now()]); DB::transaction(function () use($post) { $this->posts()->save($post); $this->refreshCache(); if ($this->forum !== null) { $this->forum->refreshCache(); } if ($post->user !== null) { $post->user->refreshForumCache($this->forum, 1); } }); return $post; }