public function getModpacks($version = 'all') { $modpacks = []; $limit = 100; $offset = 0; $input = Input::only('limit', 'offset'); if ($input['limit']) { $limit = $input['limit']; } if ($input['offset']) { $offset = $input['offset']; } if ($version == 'all') { $raw_modpacks = Modpack::select('id', 'name', 'deck', 'website', 'download_link', 'wiki_link', 'description', 'slug', 'created_at', 'updated_at')->skip($offset)->take($limit)->get(); $modpack_count = Modpack::select('id')->count(); } else { $version = $this->getVersion($version); $raw_version = MinecraftVersion::where('name', '=', $version)->first(); if (!$raw_version) { return Response::json(['error' => 'Not a valid version.']); } $version_id = $raw_version->id; $raw_modpacks = Modpack::select('id', 'name', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'created_at', 'updated_at')->where('minecraft_version_id', $version_id)->skip($offset)->take($limit)->get(); $modpack_count = Modpack::select('id')->where('minecraft_version_id', $version_id)->count(); } if (!$raw_modpacks) { return Response::json(['error' => 'No results.']); } foreach ($raw_modpacks as $modpack) { $modpacks['results'][] = ['id' => $modpack->id, 'name' => $modpack->name, 'short_description' => $modpack->deck, 'website' => $modpack->website, 'download_link' => $modpack->download_link, 'donate_link' => $modpack->website, 'wiki_link' => $modpack->wiki_link, 'description' => $modpack->description, 'slug' => $modpack->slug, 'created_at' => $modpack->created_at, 'updated_at' => $modpack->updated_at]; } $modpacks['meta'] = ['total_results' => $modpack_count, 'limit' => $limit, 'offset' => $offset]; return Response::json($modpacks); }