public function getMostRecentPostTimeAttribute() { $result = false; $latestPost = Post::select('time')->where('topic_id', $this->id)->orderBy('time', 'dec')->first(); if ($latestPost) { $result = $latestPost->time; } return $result; }
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; }