v.0.1
This commit is contained in:
22
app/controllers/Answers.php
Normal file
22
app/controllers/Answers.php
Normal 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
13
app/controllers/Posts.php
Normal 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]);
|
||||
}
|
||||
}
|
25
app/controllers/Questions.php
Normal file
25
app/controllers/Questions.php
Normal 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
16
app/controllers/Users.php
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user