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();
|
||||
}
|
||||
}
|
13
app/models/Answer.php
Normal file
13
app/models/Answer.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Models;
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Answer extends Model {
|
||||
protected $table = 'Answers';
|
||||
protected $fillable = ['answer','user_id','question_id'];
|
||||
|
||||
public function upvotes()
|
||||
{
|
||||
return $this->hasMany('\Models\Upvote');
|
||||
}
|
||||
}
|
22
app/models/Database.php
Normal file
22
app/models/Database.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Models;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class Database {
|
||||
public function __construct()
|
||||
{
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => DBDRIVER,
|
||||
'host' => DBHOST,
|
||||
'database' => DBNAME,
|
||||
'username' => DBUSER,
|
||||
'password' => DBPASS,
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
]);
|
||||
// Setup the Eloquent ORM…
|
||||
$capsule->bootEloquent();
|
||||
}
|
||||
}
|
9
app/models/Post.php
Normal file
9
app/models/Post.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Models;
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
class Post extends Model
|
||||
{
|
||||
protected $table = 'Posts';
|
||||
protected $fillable = ['post', 'user_id'];
|
||||
}
|
19
app/models/Question.php
Normal file
19
app/models/Question.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Models;
|
||||
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Question extends Model {
|
||||
protected $table = 'Questions';
|
||||
protected $fillable = ['question','user_id'];
|
||||
|
||||
public function answers()
|
||||
{
|
||||
return $this->hasMany('\Models\Answer');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('\Models\User');
|
||||
}
|
||||
}
|
10
app/models/Upvote.php
Normal file
10
app/models/Upvote.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Models;
|
||||
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Upvote extends Model {
|
||||
protected $table = 'Upvotes';
|
||||
protected $fillable = ['answer_id', 'user_id'];
|
||||
|
||||
}
|
8
app/models/User.php
Normal file
8
app/models/User.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Models;
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class User extends Model {
|
||||
protected $table = 'Users';
|
||||
protected $fillable = ['username', 'email', 'password'];
|
||||
}
|
1
app/views/intro.php
Normal file
1
app/views/intro.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
Reference in New Issue
Block a user