예제 #1
0
 /**
  * Update the specified resource in storage. Requires comment_vote_id as id
  *
  * @param  int  $id
  * @return Response
  */
 public function update(CommentVote $commentVote)
 {
     //Check user permissions
     if (!Auth::user()->can('create-comment_votes')) {
         abort(401, 'You do not have permission to vote on a comment');
     }
     // check that the user_id is correct
     if ($commentVote->user_id != Auth::user()->id) {
         //->where('user_id',Auth::user()->id)
         abort(401, "The user with the id of " . Auth::user()->id . " did not create the comment_vote with the id of (" . $commentVote->id . ")");
     }
     //Time to edit vote
     $commentVote->secureFill(Request::all());
     if (!$commentVote->save()) {
         abort(403, $commentVote->errors);
     }
     return $commentVote;
 }
 /**
  * Commend a comment
  *
  * @param  Request  $request
  * @return Response (JSON)
  */
 public function up(Request $request, Comment $comment)
 {
     $address = request()->ip();
     foreach ($this->commentVotes->forComment($comment) as $vote) {
         if ($vote->address === $address) {
             return response()->json(['votes' => $comment->voteCount, 'error' => 'This IP Address has already commended this comment']);
         }
     }
     $vote = new CommentVote();
     $vote->address = $address;
     $vote->comment_id = $comment->id;
     $vote->save();
     $comment->voteCount = $comment->voteCount + 1;
     $comment->save();
     return response()->json(['votes' => $comment->voteCount]);
 }