public function tag(Request $request) { if ($request->has('tag')) { return redirect()->route('drama.tag', [$request->input('tag')]); } else { $tagmaps = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->groupBy('tag_id')->orderBy('count', 'desc')->take(100)->get(); return view('search.tag', ['tagmaps' => $tagmaps]); } }
public function tag(Request $request, $tag) { if ($request->has('sort')) { $sort = $request->input('sort'); } else { $sort = 'tagcount'; } if ($request->has('order')) { $order = $request->input('order'); } else { $order = 'desc'; } $tag = Tag::where('name', $tag)->first(); if (!$tag) { return view('search.tag', ['message' => '未找到结果']); } if ($sort == 'tagcount') { $dramas = Tagmap::with(['drama' => function ($query) { $query->select('id', 'title', 'alias', 'sc', 'type', 'era', 'genre', 'original', 'count', 'state', 'poster_url', 'introduction'); }])->select(DB::raw('count(*) as count, drama_id'))->where('tag_id', $tag->id)->groupBy('drama_id')->orderBy('count', 'desc')->paginate(20); } else { $dramas = Drama::whereExists(function ($query) use($tag) { $query->select(DB::raw(1))->from('tagmaps')->whereRaw('tagmaps.tag_id = ' . $tag->id . ' and tagmaps.drama_id = dramas.id'); })->select('id', 'title', 'alias', 'sc', 'type', 'era', 'genre', 'original', 'count', 'state', 'poster_url', 'introduction')->orderBy($sort, 'desc')->paginate(20); } if (!$dramas || !$dramas->total()) { return view('search.tag', ['message' => '未找到结果']); } return view('drama.tag', ['tag' => $tag->name, 'dramas' => $dramas, 'sort' => $sort, 'order' => $order]); }
public function tags($id) { $tagmaps = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('user_id', $id)->groupBy('tag_id')->orderBy('count', 'desc')->get(); $user = User::find($id, ['id', 'name']); return view('user.tags', ['user' => $user, 'tagmaps' => $tagmaps]); }
public function edit(Request $request, $drama_id) { $drama = Drama::find($drama_id, ['id', 'title']); $user_id = $request->user()->id; $favorite = Favorite::select('type', 'rating', 'tags')->where('user_id', $user_id)->where('drama_id', $drama_id)->first(); $review = Review::select('title', 'content', 'visible')->where('user_id', $user_id)->where('drama_id', $drama_id)->where('episode_id', 0)->first(); $tagmaps = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('user_id', $request->user()->id)->groupBy('tag_id')->orderBy('count', 'desc')->take(15)->get(); return view('favorite.edit', ['drama' => $drama, 'favorite' => $favorite, 'review' => $review, 'tagmaps' => $tagmaps]); }
public function show(Request $request, $id) { $drama = Drama::find($id, ['id', 'title', 'alias', 'type', 'era', 'genre', 'original', 'count', 'state', 'sc', 'introduction', 'reviews']); $drama->load(['episodes' => function ($query) { $query->select('id', 'drama_id', 'title', 'alias', 'release_date', 'poster_url')->orderByRaw('release_date, id')->get(); }]); $drama->commtags = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('drama_id', $id)->groupBy('tag_id')->orderBy('count', 'desc')->take(5)->get(); if (Auth::check()) { $user_id = $request->user()->id; $drama->userFavorite = Favorite::select('id', 'type', 'rating', 'tags')->where('user_id', $user_id)->where('drama_id', $id)->first(); $drama->userTags = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('user_id', $user_id)->groupBy('tag_id')->orderBy('count', 'desc')->take(10)->get(); } return $drama; }