/**
  * @api            {get} /stickers/:slug/earners/:earntId/likes Get Sticker Earnt Likers
  * @apiGroup       Likes
  * @apiDescription Get who liked a user's completion of a sticker.
  *
  * @param Sticker $sticker
  * @param int     $id
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Sticker $sticker, $id)
 {
     $this->validateId($id);
     $likes = Like::where('earntId', $id)->orderBy('createdAt', 'DESC');
     $paginator = $likes->paginate($this->getResultsPerPage());
     return $this->response($this->paginatorToArray($paginator, 'likes'));
 }
 /**
  * @api            {get} /todo/:toDoId/likes Get To Do Likers
  * @apiGroup       Likes
  * @apiDescription Get who liked a users intention to complete a task or sticker.
  *
  * @param ToDo $toDo
  *
  * @return \Illuminate\Http\Response
  */
 public function index(ToDo $toDo)
 {
     // TODO: Implement this way
     //$toDoLikeManager = $toDo->getLikeManager();
     //$likes = $toDoLikeManager->getLikers();
     $likes = Like::where('toDoId', $toDo->id)->orderBy('createdAt', 'DESC');
     $paginator = $likes->paginate($this->getResultsPerPage());
     return $this->response($this->paginatorToArray($paginator, 'likes'));
 }
 /**
  * @param User $user
  *
  * @return int
  * @throws Exception
  */
 public function unlike(User $user)
 {
     $likes = Like::where('userId', $user->id)->where('joinId', $this->objectOrId)->get();
     if (count($likes) < 1) {
         throw new Exception("User does not like that joining");
     }
     $deleted = 0;
     foreach ($likes as $like) {
         if ($like->delete()) {
             ++$deleted;
         }
     }
     return $deleted;
 }
 /**
  * @param User $user
  *
  * @return int
  * @throws Exception
  */
 public function unlike(User $user)
 {
     $likes = Like::where('userId', $user->id)->where('earntId', $this->objectOrId)->get();
     if (count($likes) < 1) {
         throw new Exception("User does not like that earning");
     }
     $deleted = 0;
     foreach ($likes as $like) {
         if ($like->delete()) {
             ++$deleted;
         }
     }
     if ($deleted) {
         DB::statement("UPDATE user_earnt_stickers SET likeCount = likeCount - ? WHERE id = ?", [$deleted, $this->objectOrId]);
     }
     return $deleted;
 }
 /**
  * @param User $user
  *
  * @return int
  * @throws Exception
  */
 public function unlike(User $user)
 {
     if (!$this->userLikes($user)) {
         throw new Exception("User does not like that post");
     }
     $post = $this->objectOrId instanceof Post ? $this->objectOrId : Post::find($this->objectOrId);
     $likes = Like::where('userId', $user->id)->where('postId', $post->id)->get();
     $deleted = 0;
     foreach ($likes as $like) {
         if ($like->delete()) {
             ++$deleted;
         }
     }
     if ($deleted) {
         $post->likeCount -= $deleted;
         $post->save();
     }
     return $deleted;
 }
 /**
  * @param User $user
  *
  * @return int
  * @throws Exception
  */
 public function unlike(User $user)
 {
     if (!$this->userLikes($user)) {
         throw new Exception("User does not like that to do");
     }
     $toDo = $this->objectOrId instanceof ToDo ? $this->objectOrId : ToDo::find($this->objectOrId);
     $likes = Like::where('userId', $user->id)->where('toDoId', $toDo->id)->get();
     $deleted = 0;
     foreach ($likes as $like) {
         if ($like->delete()) {
             ++$deleted;
         }
     }
     if ($deleted) {
         $toDo->likeCount -= $deleted;
         $toDo->save();
     }
     return $deleted;
 }