Пример #1
0
 /**
  * Like Post Request handler for Code War Questions
  *
  * @param $war_id
  * @param Request $request
  * @return mixed
  */
 public function likeCWQ($war_id, Request $request)
 {
     //Find Answer with Current Id;
     $question = $this->codeWarQuestion->findOrFail($war_id);
     if (!$question->likes()->where('user_id', $request->user()->id)->get()->isEmpty()) {
         $question->likes()->where('user_id', $request->user()->id)->first()->delete();
         return back()->withNotification('Success! You unliked ' . $question->title);
     }
     $question->likes()->create(['user_id' => $request->user()->id]);
     return back()->withNotification('Success! You liked ' . $question->title);
 }
Пример #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)");
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $question = \App\CodeWarQuestion::findOrFail($this->code_war_question_id);
     /**
      * User already submitted an Answer to this War
      */
     if (!is_null($question->answers()->where('user_id', $this->user()->id)->first())) {
         return false;
     }
     if ($question->isOpen()) {
         return true;
     }
     return false;
 }