public function getMostRecentPostAttribute() { $post = null; $topicIDs = Topic::select('id')->where('section_id', $this->id)->get()->toArray(); $postID = Post::select('id')->whereIn('topic_id', $topicIDs)->orderBy('id', 'desc')->get()->first(); if ($postID) { $post = Post::find($postID->id); } return $post; }