This commit is contained in:
2024-07-03 14:41:15 +03:00
commit ec69208f05
1892 changed files with 181728 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace Controllers;
use Models\Answer;
use Models\Upvote;
class Answers {
public static function add_answer($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)
{
return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]);
}
public static function update_answer($answer_id,$new_answer)
{
$answer = Answer::find($answer_id);
$answer->answer = $new_answer;
return $answer->save();
}
}

13
app/controllers/Posts.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace Controllers;
use Models\Post;
class Posts
{
public static function create_post($post, $user_id)
{
return Post::create(['post'=>$post, 'user_id'=>$user_id]);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Controllers;
use Models\Question;
class Questions{
public static function create_question($question,$user_id)
{
return Question::create(['question'=>$question,'user_id'=>$user_id]);
}
public static function get_questions_with_answers()
{
return Question::with('Answers')->get()->toArray();
}
public static function get_questions_with_users()
{
return Question::with('user')->get()->toArray();
}
public static function get_question_answers_upvotes($question_id)
{
return Question::find($question_id)->answers()->with('upvotes')->get()->toArray();
}
}

16
app/controllers/Users.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Controllers;
use Models\User;
use Models\Question;
class Users {
public static function create_user($username, $email, $password)
{
return User::create(['username'=>$username,'email'=>$email,'password'=>$password]);
}
public static function question_count($user_id)
{
return Question::where('user_id', $user_id)->count();
}
}