/** * 首页 * * @param Request $request * @return Response */ public function index(Request $request) { // get params $cate = $request::get('cate', 'all'); $limit = 'all' === $cate ? $request::get('limit', 50) : 100000; $isFlush = $request::get('flush'); // cache it $cacheKey = Music::INDEX_ALL_CACHE_PREFIX . $cate; $archive = Cache::get($cacheKey); if ($isFlush or empty($archive)) { // collect data $data = []; if (in_array($cate, ['all', 'music'])) { $musics = Music::select('id', 'title', 'album', 'counts')->orderBy('counts', 'desc')->take($limit)->get(); $musicCounts = Music::count(); $data['music'] = ['list' => $musics, 'counts' => $musicCounts]; } if (in_array($cate, ['all', 'artist'])) { $artists = Artist::orderBy('counts', 'desc')->take($limit)->get(); $artistCounts = Artist::count(); $data['artist'] = ['list' => $artists, 'counts' => $artistCounts]; } // TDK $title = '飞鱼秀 の 大歌单'; if ('artist' === $cate) { $title = $title . ' - 全部歌手'; } if ('music' === $cate) { $title = $title . ' - 全部歌曲'; } $description = '飞鱼秀歌单, 飞鱼秀音乐列表'; // render $archive = (string) View::make('music.index.archive')->with('data', $data)->with('cate', $cate)->with('limit', $limit)->with('title', $title)->with('description', $description); Cache::forever($cacheKey, $archive); } // render page return View::make('music.index.frame')->with('archive', $archive); }