test routing
This commit is contained in:
@ -1,22 +1,32 @@
|
||||
<?php
|
||||
namespace Controllers;
|
||||
use Models\Answer;
|
||||
use Models\Upvote;
|
||||
namespace app\controllers;
|
||||
|
||||
|
||||
use app\models\Answer;
|
||||
use app\models\Upvote;
|
||||
|
||||
class Answers {
|
||||
public static function add_answer($answer,$question_id,$user_id)
|
||||
public function actionAddAnswer($answer,$question_id,$user_id)
|
||||
{
|
||||
return Answer::create(['answer'=>$answer,'question_id'=>$question_id,'user_id'=>$user_id]);
|
||||
}
|
||||
public static function upvote_answer($answer_id,$user_id)
|
||||
public static function actionUpvoteAnswer($answer_id,$user_id)
|
||||
{
|
||||
return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]);
|
||||
}
|
||||
|
||||
public static function update_answer($answer_id,$new_answer)
|
||||
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>";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers;
|
||||
namespace app\controllers;
|
||||
|
||||
use Models\Post;
|
||||
|
||||
use app\models\Post;
|
||||
|
||||
class Posts
|
||||
{
|
||||
public static function create_post($post, $user_id)
|
||||
public function actionCreatePost($post, $user_id)
|
||||
{
|
||||
return Post::create(['post'=>$post, 'user_id'=>$user_id]);
|
||||
}
|
||||
|
||||
public function actionViewAllPosts()
|
||||
{
|
||||
foreach (Post::all() as $post)
|
||||
{
|
||||
echo $post->post . "<br>";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,34 @@
|
||||
<?php
|
||||
namespace Controllers;
|
||||
use Models\Question;
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\Question;
|
||||
|
||||
class Questions{
|
||||
public static function create_question($question,$user_id)
|
||||
public function actionCreateQuestion($question,$user_id)
|
||||
{
|
||||
return Question::create(['question'=>$question,'user_id'=>$user_id]);
|
||||
}
|
||||
|
||||
public static function get_questions_with_answers()
|
||||
public function actionGetQuestionsWithAnswers()
|
||||
{
|
||||
return Question::with('Answers')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function get_questions_with_users()
|
||||
public function actionGetQuestionsWithUsers()
|
||||
{
|
||||
return Question::with('user')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function get_question_answers_upvotes($question_id)
|
||||
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>";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
<?php
|
||||
namespace Controllers;
|
||||
use Models\User;
|
||||
use Models\Question;
|
||||
namespace app\controllers;
|
||||
|
||||
|
||||
use app\models\Question;
|
||||
use app\models\User;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Users {
|
||||
public function actionCreateUser($username, $email, $password)
|
||||
@ -13,4 +17,22 @@ class Users {
|
||||
{
|
||||
return Question::where('user_id', $user_id)->count();
|
||||
}
|
||||
|
||||
public function actionViewAllUsers(): void
|
||||
{
|
||||
foreach (User::all() as $user)
|
||||
{
|
||||
echo $user->username . "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
public function actionViewUser(): void
|
||||
{
|
||||
echo User::where('id', '=', 13)->get();
|
||||
// $user = User::where('id', '=', 13)->get();
|
||||
|
||||
// echo $user->username . "<br>";
|
||||
// echo $user->email . "<br>";
|
||||
// echo $user->created_at . "<br>";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user