MicroFrameWork/app/controllers/QuestionController.php

35 lines
820 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-12 11:06:19 +03:00
2024-07-11 16:16:36 +03:00
class QuestionController extends Controller{
2024-07-10 14:39:37 +03:00
public function actionCreate()
2024-07-03 14:41:15 +03:00
{
2024-07-11 16:16:36 +03:00
echo $this->twig->render('questionCreate.html');
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
}