/** * Display a listing of the resource. * * @param null $categoryId * @return \Illuminate\View\View */ public function index($categoryId = null) { $categories = Category::all(); if (is_null($categoryId)) { $videos = Category::first()->videos; return view('pages.landing', compact(['categories', 'videos'])); } $videos = Category::find($categoryId)->videos; return view('pages.landing', compact(['categories', 'videos'])); }
/** * Show all the videos of a particular category. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $category = Category::find($id); return view('categories.show', ['category' => $category, 'videos' => $category->videos()->paginate(6)]); }