示例#1
0
 public static function unlikePost($input)
 {
     $validation = Validator::make($input, Posts::$likePostRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $post_id = $input['post_id'];
         $current_time = new DateTime();
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             $like_data = DB::table('likes')->select('id')->where('post_id', $post_id)->where('user_id', $user_id)->first();
             $like_id = DB::table('likes')->select('id')->where('post_id', $post_id)->where('user_id', $user_id)->delete();
             $Ninput['sender_id'] = $user_id;
             $Ninput['receiver_id'] = Posts::getPostOwner($post_id);
             $Ninput['type_id'] = $like_data->id;
             $Ninput['type'] = 'like';
             Notifications::RemoveNotification($Ninput);
             if ($like_id) {
                 return Response::json(array('status' => '1', 'msg' => 'Post Unliked'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }