Exemplo n.º 1
0
 /**
  * Like Post Request Handler for Code War Answers
  *
  * @param $war_id
  * @param $answer_id
  * @param Request $request
  * @return mixed
  */
 public function likeCWA($war_id, $answer_id, Request $request)
 {
     //Find Answer with Current Id;
     $answer = $this->codeWarAnswer->findOrFail($answer_id);
     if (!$answer->likes()->where('user_id', $request->user()->id)->get()->isEmpty()) {
         $answer->likes()->where('user_id', $request->user()->id)->first()->delete();
         return back()->withNotification('Success! You unliked ' . $answer->user->name . "'s answer");
     }
     $answer->likes()->create(['user_id' => $request->user()->id]);
     return back()->withNotification('Success! You liked ' . $answer->user->name . "'s answer");
 }
Exemplo n.º 2
0
 public function bestanswer(Request $request, $id)
 {
     $question = $this->question->findOrFail($id);
     $answer = $this->answer->findOrFail($request->best_answer_id);
     if ($answer->code_war_question_id != $question->id) {
         return back()->withNotification("Error! Intrusion Detected and Blocked.");
     }
     if ($request->user()->can('edit', $question)) {
         $question->fill($request->only('best_answer_id'))->save();
         return back()->withNotification("Success! Answer set as Best. Will be visible once this War Ends.");
     }
     return back()->withNotification("Error! Something is not right)");
 }