Exemple #1
0
 public function userIsWatching($user_id)
 {
     return ForumTopicWatch::where(['user_id' => $user_id, 'topic_id' => $this->id])->exists();
 }
 function unsubscribeFromTopic($id)
 {
     $user = Auth::user();
     $topic = ForumTopic::find($id);
     if ($user) {
         if ($topic) {
             $watch = ForumTopicWatch::where(['user_id' => $user->id, 'topic_id' => $topic->id])->first();
             if ($watch) {
                 $watch->delete();
                 return true;
             } else {
                 return Response::json(["success" => false, "message" => "Watch not found."]);
             }
         } else {
             return Response::json(["success" => false, "message" => "Topic not found."]);
         }
     } else {
         return Response::json(["success" => false, "message" => "Unauthorized."]);
     }
 }