예제 #1
0
 public function upvote($id, Request $request)
 {
     //upvote reply
     $reply = Reply::find($id);
     //notify commenter
     if (Auth::check()) {
         App('App\\Notification')->notify('reply_upvote', Auth::user(), $reply->user, $reply->article, $reply);
         if ($reply->votes()->ByWhom(Auth::id())->count()) {
             // click twice for remove upvote
             $reply->votes()->ByWhom(Auth::id())->delete();
             $reply->decrement('vote_count', 1);
             $reply->article()->decrement('vote_count', 1);
         } else {
             // first time click
             $reply->votes()->create(['user_id' => Auth::id()]);
             $reply->increment('vote_count', 1);
             $reply->article()->increment('vote_count', 1);
         }
     } else {
         //匿名投票
         App('App\\Notification')->nonamenotify('reply_upvote', $reply->user, $reply->article, $reply);
         if ($reply->votes()->ByWhom($request->ip())->count()) {
             $reply->votes()->ByWhom($request->ip())->delete();
             $reply->decrement('vote_count', 1);
         } else {
             $reply->votes()->create(['user_id' => $request->ip()]);
             $reply->increment('vote_count', 1);
         }
     }
     return $reply->vote_count;
 }
예제 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $Reply = Reply::find($id);
     if ($Reply->type_id == Reply::TYPE_CONTENT) {
         $Content = $Reply->entity;
         $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-content-replys';
     } else {
         if ($Reply->type_id == Reply::TYPE_COMMENT) {
             $Comment = $Reply->entity;
             $Content = $Comment->entity;
             $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-comment-replys-' . $Comment->id;
         }
     }
     return redirect()->to($route);
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $reply = Reply::find($id);
     if ($reply->user_id == Auth::id()) {
         if ($reply->delete()) {
             DB::table('reviews')->where('id', $reply->review_id)->decrement('replies');
         }
     }
     return redirect()->back();
 }
예제 #4
0
 public function vote($id)
 {
     $reply = Reply::find($id);
     app('App\\Services\\Voter')->replyUpVote($reply);
     return redirect()->route('topics.show', [$reply->topic_id, '#reply' . $reply->id]);
 }
 public function vote($id)
 {
     $reply = Reply::find($id);
     app('App\\good\\Vote\\Voter')->replyUpVote($reply);
     return Redirect::route('topics.show', [$reply->topic_id, '#reply' . $reply->id]);
 }