For Monday

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

@ -3,7 +3,9 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Thread; use App\Thread;
use App\Http\Resources\ThreadsCollection;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection;
class ThreadController extends Controller class ThreadController extends Controller
{ {
@ -14,9 +16,7 @@ class ThreadController extends Controller
*/ */
public function index() public function index()
{ {
$threads = Thread::orderBy('created_at', 'desc')->paginate(20); return new ThreadsCollection(Thread::with("creator")->get()->sortByDesc('created_at'));
return Thread::collection($threads);
} }
/** /**

@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ThreadsCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection
];
}
public function getCreators() {
foreach($this->collection as &$t) {
$creator = $t->creator;
//dd($creator->name);
$t->creator_name = $creator->name;
}
dd($this->collection);
}
}

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Thread extends Model class Thread extends Model
{ {
// private $creator_name;
/** /**
* Get the creator of the thread. * Get the creator of the thread.

@ -11,6 +11,10 @@ class DatabaseSeeder extends Seeder
*/ */
public function run() public function run()
{ {
// $this->call(UsersTableSeeder::class); $this->call(UsersTableSeeder::class);
$this->call(ThreadsTableSeeder::class);
$this->call(PostsTableSeeder::class);
$this->call(TagsTableSeeder::class);
$this->call(TagThreadTableSeeder::class);
} }
} }

@ -11,6 +11,16 @@ class PostsTableSeeder extends Seeder
*/ */
public function run() public function run()
{ {
// DB::table('posts')->insert([
'content' => 'Seriously every Fortnite player is 12',
'poster_id' => 7,
'thread_id' => 2
]);
DB::table('posts')->insert([
'content' => "I'm 13 actually!",
'poster_id' => 3,
'thread_id' => 2
]);
} }
} }

@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Seeder;
class TagThreadTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('tag_thread')->insert([
'tag_id' => 1,
'thread_id' => 2
]);
DB::table('tag_thread')->insert([
'tag_id' => 2,
'thread_id' => 2
]);
}
}

@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Seeder;
class TagsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('tags')->insert([
'tag_text' => "Fortnite",
'creator_id' => 1
]);
DB::table('tags')->insert([
'tag_text' => "Multiplayer",
'creator_id' => 1
]);
}
}

@ -11,22 +11,38 @@ class ThreadsTableSeeder extends Seeder
*/ */
public function run() public function run()
{ {
$titles = array([ /*$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", "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?", "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?" "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++) { $i=0;
for($i; $i<9; $i++) {
$title = $titles[$i];
$creator = $i+2;
DB::table('threads')->insert([ DB::table('threads')->insert([
'thread_title' => $titles[$i], 'thread_title' => $title,
'thread_creator_id' => $i+2 'thread_creator_id' => $creator
]); ]);
} }*/
DB::table('threads')->insert([ DB::table('threads')->insert([
'thread_title' => "Welcome to GameGab!", 'thread_title' => "Welcome to GameGab!",
'thread_creator_id' => 1 'thread_creator_id' => 1,
'created_at' => date('Y-m-d H:i:s')
]);
DB::table('threads')->insert([
'thread_title' => "Is everyone who plays Fortnite 12 years old?",
'thread_creator_id' => 2,
'created_at' => date('Y-m-d H:i:s')
]);
DB::table('threads')->insert([
'thread_title' => "WHY ARE THERE SO MANY ASSASSIN'S CREED GAMES",
'thread_creator_id' => 3,
'created_at' => date('Y-m-d H:i:s')
]); ]);
} }
} }

9144
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -20,6 +20,7 @@
"resolve-url-loader": "^2.3.1", "resolve-url-loader": "^2.3.1",
"sass": "^1.15.2", "sass": "^1.15.2",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",
"vue": "^2.5.17" "vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
} }
} }

10664
public/css/app.css vendored

File diff suppressed because one or more lines are too long

49199
public/js/app.js vendored

File diff suppressed because one or more lines are too long

@ -0,0 +1,4 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}

@ -1,4 +1,12 @@
<template>
<div>
<h2>Browse Threads</h2>
<div class="card card-body" v-for="thread in threads" v-bind:key="thread.id">
<p>{{ thread.creator.name }}
<h3>{{ thread.thread_title }}</h3>
</div>
</div>
</template>
<script> <script>
export default { export default {
@ -7,11 +15,12 @@ export default {
threads: [], threads: [],
thread: { thread: {
id: '', id: '',
title: '', thread_title: '',
creator: '' creator: {
name: ''
},
}, },
thread_id: '', thread_id: '',
pagination: {},
edit: false edit: false
} }
}, },
@ -23,10 +32,10 @@ export default {
methods: { methods: {
fetchThreads() { fetchThreads() {
fetch("api/threads") fetch("api/threads")
.then(res => json()) .then(res => res.json())
.then(res => { .then(res => {
console.log(res.data); this.threads = res.data;
}) });
} }
} }
} }

@ -0,0 +1,9 @@
@extends('layouts.app')
@section('content')
<div id="app">
<div class="container">
<thread-component></thread-component>
</div>
</div>
@endsection

@ -18,3 +18,7 @@ Route::get('/', function () {
Auth::routes(); Auth::routes();
Route::get('/home', 'HomeController@index')->name('home'); Route::get('/home', 'HomeController@index')->name('home');
Route::get('/test', function() {
return view("dashboard");
});

Loading…
Cancel
Save