committing because I'm paranoid

pull/2/head
Braydon Kains 6 years ago
parent 811cb953a3
commit b6890ce2c2

@ -14,7 +14,9 @@ class ThreadController extends Controller
*/
public function index()
{
//
$threads = Thread::orderBy('created_at', 'desc')->paginate(20);
return Thread::collection($threads);
}
/**
@ -24,7 +26,7 @@ class ThreadController extends Controller
*/
public function create()
{
//
return view("create_thread");
}
/**
@ -35,7 +37,12 @@ class ThreadController extends Controller
*/
public function store(Request $request)
{
//
$thread = new Thread;
$thread->thread_title = $request->thread_title;
$thread->thread_poster_id = $request->user_id;
$thread->save();
}
/**
@ -46,7 +53,7 @@ class ThreadController extends Controller
*/
public function show(Thread $thread)
{
//
return view("thread_view")->withThread($thread);
}
/**

@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//
/**
* Get the poster of the post.
*/
public function poster() {
return $this->belongsTo('App\User', 'poster_id');
}
}

@ -6,5 +6,17 @@ use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
//
/**
* Get threads that have this tag.
*/
public function threads() {
return $this->belongsToMany('App\Thread');
}
/**
* Get creator of this tag.
*/
public function creator() {
return $this->belongsTo('App\User', 'creator_id');
}
}

@ -7,4 +7,18 @@ use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
//
/**
* Get the creator of the thread.
*/
public function creator() {
return $this->belongsTo('App\User', 'thread_creator_id');
}
/**
* Get the tags for the thread.
*/
public function tags() {
return $this->belongsToMany('App\Tag');
}
}

@ -36,4 +36,25 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Get the threads the user has posted.
*/
public function threads() {
return $this->hasMany('App\Thread');
}
/**
* Get the posts the user has made.
*/
public function posts() {
return $this->hasMany('App\Post');
}
/**
* Get the tags the user has created.
*/
public function tags() {
return $this->hasMany('App\Tag');
}
}

@ -1,31 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateForumsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('forums', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('forums');
}
}

@ -14,8 +14,17 @@ class CreateThreadsTable extends Migration
public function up()
{
Schema::create('threads', function (Blueprint $table) {
//Columns
$table->bigIncrements('id');
$table->string('thread_title');
$table->unsignedBigInteger('thread_creator_id')->nullable();
$table->timestamps();
//Key constraints
$table->foreign('thread_creator_id')->
references('id')->
on('users')->
onDelete('set null');
});
}

@ -14,8 +14,23 @@ class CreatePostsTable extends Migration
public function up()
{
Schema::create('posts', function (Blueprint $table) {
//Columns
$table->bigIncrements('id');
$table->string('content');
$table->unsignedBigInteger('poster_id')->nullable();
$table->unsignedBigInteger('thread_id');
$table->timestamps();
//Key constraints
$table->foreign('poster_id')->
references('id')->
on('users')->
onDelete('set null');
$table->foreign('thread_id')->
references('id')->
on('threads')->
onDelete('cascade');
});
}

@ -14,8 +14,17 @@ class CreateTagsTable extends Migration
public function up()
{
Schema::create('tags', function (Blueprint $table) {
//Columns
$table->bigIncrements('id');
$table->string('tag_text');
$table->unsignedBigInteger('creator_id')->nullable();
$table->timestamps();
//Key Constraints
$table->foreign('creator_id')
->references('id')
->on('users')
->onDelete('set null');
});
}

@ -0,0 +1,45 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class TagThread extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create("tag_thread", function(Blueprint $table) {
//Columns
$table->bigIncrements('id');
$table->unsignedBigInteger('tag_id');
$table->foreign('tag_id')
->references('id')
->on('tags')
->onDelete('cascade');
$table->unsignedBigInteger('thread_id');
$table->foreign('thread_id')
->references('id')
->on('threads')
->onDelete('cascade');
//Key constraints
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tag_thread');
}
}

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class PostsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
}
}

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Seeder;
class ThreadsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$titles = array([
"WHY ARE THERE SO MANY ASSASSIN'S CREED GAMES", "This new Yoshi game is awesome!", "I am better at Fortnite than all my friends I am 12",
"This new Yoshi game is awesome!", "OMG!!! Bowser took over Nintendo!", "Grant Kirkhope the best video game composer ever?",
"The coolest Devil May Cry V autocombos", "Sekiro should respect it's playerbase and add an easy mode", "Is everyone who plays Fortnite 12 years old?"
]);
for($i = 0; $i<9; $i++) {
DB::table('threads')->insert([
'thread_title' => $titles[$i],
'thread_creator_id' => $i+2
]);
}
DB::table('threads')->insert([
'thread_title' => "Welcome to GameGab!",
'thread_creator_id' => 1
]);
}
}

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
'name' => 'GameGabTeam',
'email' => Str::random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
for($i=0; $i<10; $i++) {
DB::table('users')->insert([
'name' => Str::random(10),
'email' => Str::random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
}
}
}

@ -20,7 +20,7 @@ window.Vue = require('vue');
// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('thread-component', require('./components/ThreadComponent.vue').default);
/**
* Next, we will create a fresh Vue application instance and attach it to

@ -1,5 +0,0 @@
<template>
<div class="login">
<div v-if="loginStart" class=""
</div>
</template>

@ -0,0 +1,33 @@
<script>
export default {
data() {
return {
threads: [],
thread: {
id: '',
title: '',
creator: ''
},
thread_id: '',
pagination: {},
edit: false
}
},
created() {
this.fetchThreads();
},
methods: {
fetchThreads() {
fetch("api/threads")
.then(res => json())
.then(res => {
console.log(res.data);
})
}
}
}
</script>

@ -16,3 +16,5 @@ use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('threads', 'ThreadController@index');
Loading…
Cancel
Save