34 lines
		
	
	
		
			815 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			815 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| namespace app\controllers;
 | |
| 
 | |
| use app\models\Question;
 | |
| 
 | |
| class Questions{
 | |
|     public function actionCreateQuestion($question,$user_id)
 | |
|     {
 | |
|         return Question::create(['question'=>$question,'user_id'=>$user_id]);
 | |
|     }
 | |
| 
 | |
|     public function actionGetQuestionsWithAnswers()
 | |
|     {
 | |
|         return Question::with('Answers')->get()->toArray();
 | |
|     }
 | |
| 
 | |
|     public function actionGetQuestionsWithUsers()
 | |
|     {
 | |
|         return Question::with('user')->get()->toArray();
 | |
|     }
 | |
| 
 | |
|     public function actionGetQuestionAnswersUpvotes($question_id)
 | |
|     {
 | |
|         return Question::find($question_id)->answers()->with('upvotes')->get()->toArray();
 | |
|     }
 | |
| 
 | |
|     public function actionViewAllQuestions()
 | |
|     {
 | |
|         foreach (Question::all() as $question)
 | |
|         {
 | |
|             echo $question->question. "<br>";
 | |
|         }
 | |
|     }
 | |
| } |