/**
  * Display the specified resource.
  *
  * @param  string  $shortname
  * @param int $id
  * @return \Response
  */
 public function showVideo($shortname, $id = null)
 {
     $category = Category::whereShortname($shortname)->first();
     if (is_null($category)) {
         return redirect()->back()->with('error', 'Category not found');
     }
     if (is_null($id)) {
         $id = Video::whereCategoryId($category->id)->count() - 1;
         if ($id < 0) {
             return redirect()->back()->with('error', 'Category is empty.');
         }
         $id = rand(0, $id);
         $video = Video::whereCategoryId($category->id)->skip($id)->first();
         return redirect($shortname . '/' . $video->id);
     } else {
         $video = Video::whereCategoryId($category->id)->find($id);
     }
     if (is_null($video)) {
         return redirect()->back()->with('error', 'Category is empty.');
     }
     return view('video', ['video' => $video, 'category' => true]);
 }
Example #2
0
 /**
  * Display the specified resource.
  *
  * @param  string  $shortname
  * @param int $id
  * @return \Response
  */
 public function showVideo($shortname, $id = null)
 {
     // GZ's kläglicher versuch:
     //if(!auth()->check()) return redirect('/irc')->with('error', 'You need to be logged in to view our content');
     $category = Category::whereShortname($shortname)->first();
     if (is_null($category)) {
         return redirect()->back()->with('error', 'Category not found');
     }
     if (is_null($id)) {
         $id = Video::whereCategoryId($category->id)->count() - 1;
         if ($id < 0) {
             return redirect()->back()->with('error', 'Category is empty.');
         }
         $id = rand(0, $id);
         $video = Video::whereCategoryId($category->id)->skip($id)->first();
         return redirect($shortname . '/' . $video->id);
     } else {
         $video = Video::whereCategoryId($category->id)->find($id);
     }
     if (is_null($video)) {
         return redirect()->back()->with('error', 'Category is empty.');
     }
     return view('video', ['video' => $video, 'category' => true]);
 }