MicroFrameWork/app/controllers/Questions.php

34 lines
815 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
class Questions{
2024-07-05 13:49:04 +03:00
public function actionCreateQuestion($question,$user_id)
2024-07-03 14:41:15 +03:00
{
return Question::create(['question'=>$question,'user_id'=>$user_id]);
}
2024-07-05 13:49:04 +03:00
public function actionGetQuestionsWithAnswers()
2024-07-03 14:41:15 +03:00
{
return Question::with('Answers')->get()->toArray();
}
2024-07-05 13:49:04 +03:00
public function actionGetQuestionsWithUsers()
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
}