backend/app/controllers/QuestionController.php

34 lines
797 B
PHP
Raw Normal View History

2024-07-03 14:41:15 +03:00
<?php
2024-07-05 13:49:04 +03:00
namespace app\controllers;
use app\models\Question;
2024-07-03 14:41:15 +03:00
2024-07-09 16:08:50 +03:00
class QuestionController{
2024-07-12 11:03:48 +03:00
public function actionCreate(): void
2024-07-03 14:41:15 +03:00
{
2024-07-10 14:39:37 +03:00
require "app/views/questionCreate.php";
2024-07-03 14:41:15 +03:00
}
2024-07-12 11:03:48 +03:00
public function actionGetQuestionsWithAnswers(): array
2024-07-03 14:41:15 +03:00
{
2024-07-09 16:08:50 +03:00
return Question::with('AnswerController')->get()->toArray();
2024-07-03 14:41:15 +03:00
}
2024-07-12 11:03:48 +03:00
public function actionGetQuestionsWithUsers(): array
2024-07-03 14:41:15 +03:00
{
return Question::with('user')->get()->toArray();
}
2024-07-05 13:49:04 +03:00
public function actionGetQuestionAnswersUpvotes($question_id)
2024-07-03 14:41:15 +03:00
{
return Question::find($question_id)->answers()->with('upvotes')->get()->toArray();
}
2024-07-05 13:49:04 +03:00
public function actionViewAllQuestions()
{
foreach (Question::all() as $question)
{
echo $question->question. "<br>";
}
}
2024-07-03 14:41:15 +03:00
}