public function epfavs(Request $request, $id, $type) { if ($request->has('sort')) { $sort = $request->input('sort'); } else { $sort = 'updated_at'; } $favorites = Epfav::with(['episode' => function ($query) { $query->join('dramas', 'dramas.id', '=', 'episodes.drama_id')->select('episodes.id as id', 'dramas.title as dramaTitle', 'episodes.title as title', 'dramas.sc as cv', 'episodes.duration as duration'); }])->select('episode_id', 'type', 'rating', 'updated_at')->where('user_id', $id)->where('type', $type)->orderBy($sort, 'desc')->simplePaginate(20); return $favorites; }
public function favorites($id) { $episode = Episode::find($id, ['id', 'drama_id', 'title']); $drama = Drama::find($episode->drama_id, ['title']); $favorites = Epfav::with(['user' => function ($query) { $query->select('id', 'name'); }])->select('user_id', 'type', 'updated_at')->where('episode_id', $id)->orderBy('updated_at')->paginate(20); return view('episode.favorites', ['episode' => $episode, 'drama' => $drama, 'favorites' => $favorites]); }
public function epfavs(Request $request, $id, $type) { $user = User::find($id, ['id', 'name']); if ($request->has('sort')) { $sort = $request->input('sort'); } else { $sort = 'updated_at'; } $favorites = Epfav::with(['episode' => function ($query) { $query->join('dramas', 'dramas.id', '=', 'episodes.drama_id')->select('episodes.id as id', 'drama_id', 'dramas.title as drama_title', 'episodes.title as title', 'dramas.sc as cv', 'episodes.duration as duration'); }])->select('episode_id', 'type', 'rating', 'updated_at')->where('user_id', $id)->where('type', $type)->orderBy($sort, 'desc')->paginate(20); return view('user.epfavs', ['user' => $user, 'type' => $type, 'favorites' => $favorites, 'sort' => $sort]); }