backend/app/controllers/Answers.php
2024-07-05 13:49:04 +03:00

32 lines
794 B
PHP

<?php
namespace app\controllers;
use app\models\Answer;
use app\models\Upvote;
class Answers {
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>";
}
}
}