test routing
This commit is contained in:
parent
a482a508e4
commit
2f2310e739
@ -1,22 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Controllers;
|
namespace app\controllers;
|
||||||
use Models\Answer;
|
|
||||||
use Models\Upvote;
|
|
||||||
|
use app\models\Answer;
|
||||||
|
use app\models\Upvote;
|
||||||
|
|
||||||
class Answers {
|
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]);
|
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]);
|
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::find($answer_id);
|
||||||
$answer->answer = $new_answer;
|
$answer->answer = $new_answer;
|
||||||
return $answer->save();
|
return $answer->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionViewAllAnswers(): void
|
||||||
|
{
|
||||||
|
foreach (Answer::all() as $answer)
|
||||||
|
{
|
||||||
|
echo $answer->answer . "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,13 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Controllers;
|
namespace app\controllers;
|
||||||
|
|
||||||
use Models\Post;
|
|
||||||
|
use app\models\Post;
|
||||||
|
|
||||||
class Posts
|
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]);
|
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
|
<?php
|
||||||
namespace Controllers;
|
namespace app\controllers;
|
||||||
use Models\Question;
|
|
||||||
|
use app\models\Question;
|
||||||
|
|
||||||
class Questions{
|
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]);
|
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();
|
return Question::with('Answers')->get()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_questions_with_users()
|
public function actionGetQuestionsWithUsers()
|
||||||
{
|
{
|
||||||
return Question::with('user')->get()->toArray();
|
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();
|
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
|
<?php
|
||||||
namespace Controllers;
|
namespace app\controllers;
|
||||||
use Models\User;
|
|
||||||
use Models\Question;
|
|
||||||
|
use app\models\Question;
|
||||||
|
use app\models\User;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class Users {
|
class Users {
|
||||||
public function actionCreateUser($username, $email, $password)
|
public function actionCreateUser($username, $email, $password)
|
||||||
@ -13,4 +17,22 @@ class Users {
|
|||||||
{
|
{
|
||||||
return Question::where('user_id', $user_id)->count();
|
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>";
|
||||||
|
}
|
||||||
}
|
}
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
15
index.php
15
index.php
@ -3,10 +3,10 @@ require_once "vendor/autoload.php";
|
|||||||
require 'bootstrap.php';
|
require 'bootstrap.php';
|
||||||
|
|
||||||
use app\controllers\MainController;
|
use app\controllers\MainController;
|
||||||
use Controllers\Users;
|
use app\controllers\Users;
|
||||||
use Controllers\Questions;
|
use app\controllers\Questions;
|
||||||
use Controllers\Answers;
|
use app\controllers\Answers;
|
||||||
use Controllers\Posts;
|
use app\controllers\Posts;
|
||||||
use Phroute\Phroute\RouteCollector;
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +14,13 @@ $router = new RouteCollector();
|
|||||||
|
|
||||||
$router->get('/', [MainController::class, 'actionIndex']);
|
$router->get('/', [MainController::class, 'actionIndex']);
|
||||||
$router->get('/example', [MainController::class, 'actionExample']);
|
$router->get('/example', [MainController::class, 'actionExample']);
|
||||||
|
//$router->get('/createUser', [Users::class, 'actionCreateUser']);
|
||||||
|
$router->get('/allUsers', [Users::class, 'actionViewAllUsers']);
|
||||||
|
$router->get('/User', [Users::class, 'actionViewUser'], ['3']);
|
||||||
|
$router->get('/allQuestions', [Questions::class, 'actionViewAllQuestions']);
|
||||||
|
$router->get('/allPosts', [Posts::class, 'actionViewAllPosts']);
|
||||||
|
$router->get('/allAnswers', [Answers::class, 'actionViewAllAnswers']);
|
||||||
|
|
||||||
|
|
||||||
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
|
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user