Exemple #1
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $user = Auth::user();
     $reply = Reply::findOrFail($this->route('id'));
     $this->reply = $reply;
     if ($user && ($reply->user_id == $user->id && !$reply->topic->is_blocked || $user->can('manage_posts'))) {
         return true;
     } else {
         return false;
     }
 }
Exemple #2
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check()) {
         $user = Auth::user();
         $reply = Reply::findOrFail($this->route('id'));
         if ($reply->user_id == $user->id || $user->can('manage_posts')) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Exemple #3
0
 public function markAnswer(AnswerReply $request, $id)
 {
     //Pažymim atsakymą.
     $reply = Reply::findOrFail($id);
     $reply->is_answer = 1;
     $reply->user->increment('karma_count', 5);
     $reply->save();
     //Užrakinam temą.
     $topic = Topic::findOrFail($reply->topic_id);
     $topic->is_blocked = 1;
     $topic->is_answered = 1;
     $topic->save();
     flash()->success('Pranešimas pažymėtas kaip atsakymas!');
     return redirect()->route('topic.show', [$topic->slug]);
 }
Exemple #4
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check()) {
         //if user owns the topic or if user is admin
         $reply = Reply::findOrFail($this->route('id'));
         $topic = $reply->topic;
         $this->reply = $reply;
         if ($topic->user_id == Auth::user()->id || Auth::user()->can('manage_topics')) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Exemple #5
0
 public function vote(VoteRequest $request, $vote, $type, $id)
 {
     $user = Auth::user();
     if ($type == 'tema') {
         $type = 'Topic';
         $_votable = Topic::findOrFail($id);
     } else {
         $type = 'Reply';
         $_votable = Reply::findOrFail($id);
     }
     $_vote = Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->first();
     //Ištrinam visus balsus, jei netyčia susibugintų.
     if ($_vote) {
         Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->delete();
         if ($_vote->is != $vote) {
             $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
             //cancel old vote and give new vote
             if ($vote == 'upvote') {
                 event(new UpVoted($_votable, $created_vote, $_votable->user, true));
             } else {
                 event(new DownVoted($_votable, $created_vote, $_votable->user, true));
             }
         } else {
             //cancel current vote
             if ($vote == 'upvote') {
                 event(new DownVoted($_votable, $_vote, $_votable->user, false));
             } else {
                 event(new UpVoted($_votable, $_vote, $_votable->user, false));
             }
         }
     } else {
         $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
         //just vote
         if ($vote == 'upvote') {
             event(new UpVoted($_votable, $created_vote, $_votable->user, false));
         } else {
             event(new DownVoted($_votable, $created_vote, $_votable->user, false));
         }
     }
     return response('success', 200);
 }