public static function withTopic($topic) { $posts = []; foreach (Post::orderBy('id', 'desc')->get() as $post) { if ($post->topic->slug == $topic) { $posts[] = $post; } } return $posts; }