This commit is contained in:
2024-07-09 16:08:50 +03:00
parent 2c199f1ce1
commit e588866a92
13 changed files with 219 additions and 186 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace app\controllers;
use app\models\Answer;
use app\models\Upvote;
class AnswerController {
public function actionAddAnswer($answer,$question_id,$user_id)
{
return Answer::create(['answer'=>$answer,'question_id'=>$question_id,'user_id'=>$user_id]);
}
public static function actionUpvoteAnswer($answer_id,$user_id)
{
return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]);
}
public function actionUpdateAnswer($answer_id,$new_answer)
{
$answer = Answer::find($answer_id);
$answer->answer = $new_answer;
return $answer->save();
}
public function actionViewAllAnswers(): void
{
foreach (Answer::all() as $answer)
{
echo $answer->answer . "<br>";
}
}
}