public function content($id, \Illuminate\Http\Request $request)
 {
     if (preg_match('/[0-9]/', substr(strrchr($id, "-"), 1))) {
         $id = substr(strrchr($id, "-"), 1);
         if (Auth::user()) {
             $usr = User::findOrFail(Auth::user()->id);
             Useraction::where('crefid', '=', $id)->update(['is_seen' => '1']);
         }
         $notif = self::getNotif();
         $content = Content::where('id', '=', $id)->where('isvisible', '=', '1')->get();
         if (!$content->isEmpty()) {
             $content[0]->like = -1;
             $content[0]->comment = -1;
             $content[0]->report = -1;
             // return $content;
             if (Auth::user()) {
                 $u1 = Useraction::where('userid', '=', Auth::user()->id)->where('crefid', '=', $content[0]->id)->where('actiontype', '=', 'Like')->orWhere('actiontype', '=', 'Unlike')->get();
                 if (!$u1->isEmpty()) {
                     if ($u1[0]->actiontype == "Like") {
                         $content[0]->like = 1;
                     }
                 }
             }
             $userAction = Useraction::where('crefid', '=', $id)->where('actiontype', '=', 'Comment')->orderby('created_at', 'DESC')->get();
             if (!$userAction->isEmpty()) {
                 $id = 0;
                 foreach ($userAction as $u) {
                     $user = User::where('id', '=', $u->userid)->get();
                     $userAction[$id]->avatar = $user[0]->avatar;
                     $userAction[$id]->username = $user[0]->username;
                     if ($userAction[$id]->created_at->diffInSeconds(Carbon::now()) < 60) {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->diffInSeconds(Carbon::now()) . " sec";
                     } elseif ($userAction[$id]->created_at->diffInMinutes(Carbon::now()) < 60) {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->diffInMinutes(Carbon::now()) . " min";
                     } elseif ($userAction[$id]->created_at->diffInHours(Carbon::now()) < 24) {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->diffInHours(Carbon::now()) . " hrs";
                     } elseif ($userAction[$id]->created_at->diffInDays(Carbon::now()) <= 30) {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->diffInDays(Carbon::now()) . " days";
                     } elseif ($userAction[$id]->created_at->diffInMonths(Carbon::now()) <= 12) {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->diffInMonths(Carbon::now()) . " months";
                     } else {
                         $userAction[$id]->datediff = $userAction[$id]->created_at->format('M Y');
                     }
                     $id++;
                 }
                 // return $userAction[0];
                 //  return View::make('content.comments', compact('userAction','content'));
             }
             $cont = Content::orderby('pscore', 'DESC')->take(10)->get();
             $tagname = "Trending";
             //   return "userActions = ".$userAction."   content = ".$content."    cont  = ".$cont."   notif =".$notif;
             return view('content.contentDetails', compact('userAction', 'content', 'cont', 'notif', 'tagname'));
         }
     } else {
         $notif = self::getNotif();
         if ($id == "Trending") {
             return Redirect::to('/');
         } elseif ($id == "Fresh") {
             $tagname = "Fresh";
             $cont = Content::where('isvisible', '=', '1')->orderby('created_at', 'DESC')->take(10)->get();
             $trend = Content::where('isvisible', '=', '1')->orderby('pscore', 'DESC')->take(10)->get();
         } else {
             $tagname = $id;
             $tag = Tag::where('tagname', '=', $id)->get();
             //return $tag;
             //     return ($tag[0]->content_list);
             $cont = Content::where('isvisible', '=', '1')->find($tag[0]->content_list)->take(5);
             // dd($cont);
             $trend = Content::whereIn('id', $tag[0]->content_list)->where('isvisible', '=', '1')->orderby('pscore', 'DESC')->take(10)->get();
             //  $cont[0]->like=1;
         }
         $id = 0;
         foreach ($cont as $c) {
             Content::where('id', '=', $c->id)->update(['nviews' => $c->nviews + 1]);
             Content::where('id', '=', $c->id)->update(['pscore' => $c->pscore + 1]);
             $cont[$id]->like = -1;
             $cont[$id]->comment = -1;
             $cont[$id]->report = -1;
             if (Auth::user()) {
                 // use any of 2 methods both works
                 //   $userActions = Useraction::whereRaw('userid = ? and crefid = ?',[Auth::user()->id,$c->id])->get();
                 $userActions = Useraction::where('userid', '=', Auth::user()->id)->where('crefid', '=', $c->id)->get();
                 foreach ($userActions as $u) {
                     if ($u->actiontype == "Like") {
                         $cont[$id]->like = 1;
                     }
                     if ($u->actiontype == "Comment") {
                         $cont[$id]->comment = 1;
                     }
                     if ($u->actiontype == "Flag") {
                         $cont[$id]->report = 1;
                     }
                 }
                 $id++;
                 Auth::user()->update(['mplaypoints' => Auth::user()->mplaypoints + 1]);
                 Auth::user()->update(['loyaltypoints' => Auth::user()->loyaltypoints + 1]);
             }
         }
         // return $cont;
         //$cont = Content::paginate(2);
         //  dd($cont[0]->tags[0]->tagname);
         //   return($tag[0]->tagname);
         return view('content.index', compact('cont', 'tagname', 'trend', 'notif', 'tag'));
     }
 }