/** * Index/home page * * @param Request $request * @return \Illuminate\Http\Response */ public function homePage(Request $request) { $recent = $this->recentVideos(); $categories = $this->getCategory(); $videos = Video::orderBy('id', 'asc')->paginate(9); return view('pages.home', compact('categories', 'videos', 'recent')); }
/** * Get the videos uploaded by a particular use * * @param Request $request * @return \Illuminate\Http\Response */ public function myVideos(Request $request) { $recent = $this->recentVideos(); $categories = $this->getCategory(); $videos = Video::where('user_id', $request->user()->id)->orderBy('created_at', 'desc')->paginate(9); return view('pages.videos', compact('videos', 'categories', 'recent')); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request) { $recent = $this->recentVideos(); $categories = Category::orderBy('name', 'asc')->get(); $videos = Video::where('title', 'ILIKE', '%' . $request->search . '%')->paginate(9); return view('pages.search', compact('videos', 'categories', 'recent')); }
/** * Get videos in a particular category * * @param $name * @return \Illuminate\Http\Response */ public function getVideoInCategory($name) { $recent = $this->recentVideos(); $categories = $this->getCategory(); $category = Category::where('name', $name)->first(); $videos = Video::where('category_id', $category->id)->orderBy('created_at', 'desc')->paginate(9); return view('pages.category', compact('videos', 'categories', 'recent')); }
/** * Get 5 most recent videos added * * @param none * @return \Illuminate\Support\Collection */ public function recentVideos() { return Video::orderBy('created_at', 'desc')->limit(5)->get(); }
/** * Delete video * * @param $id * * @return json */ public function deleteVideo($id) { $deleteVideo = Video::where('id', $id)->delete(); if ($deleteVideo) { $this->response = ["message" => "Video deleted successfully", "status_code" => 202, "url" => "/"]; } else { $this->response = ["message" => "Unable to delete Video", "status_code" => 400]; } return $this->response; }
/** * Create Video * * @return \Illuminate\Support\Collection */ public function createVideo() { Video::create(['user_id' => 1, 'category_id' => 1, 'title' => 'Test-Title', 'url' => 'sample video', 'description' => 'Sample video description', 'slug' => 'Test-Title']); }