From f440039cf28f525326590d4a506c0253f5bdaebb Mon Sep 17 00:00:00 2001 From: Braydon Kains Date: Mon, 8 Apr 2019 22:13:52 -0400 Subject: [PATCH] Committing because I haven't in quite a while --- app/Http/Controllers/PostController.php | 31 +++++++++++------------ app/Http/Controllers/TagController.php | 2 +- app/Http/Controllers/ThreadController.php | 11 +++++--- app/Http/Resources/PostCollection.php | 21 +++++++++++++++ app/Http/Resources/TagCollection.php | 21 +++++++++++++++ app/Http/Resources/ThreadsCollection.php | 3 +++ app/Thread.php | 9 +++++-- 7 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 app/Http/Resources/PostCollection.php create mode 100644 app/Http/Resources/TagCollection.php diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index f07d242..8984b26 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Post; +use App\PostCollection; use Illuminate\Http\Request; class PostController extends Controller @@ -10,9 +11,10 @@ class PostController extends Controller /** * Display a listing of the resource. * + * @param integer $thread_id * @return \Illuminate\Http\Response */ - public function index() + public function index(Thread $thread) { // } @@ -22,9 +24,9 @@ class PostController extends Controller * * @return \Illuminate\Http\Response */ - public function create() + public function create(Thread $thread) { - // + return view("create_post")->withThread($thread); } /** @@ -35,18 +37,13 @@ class PostController extends Controller */ public function store(Request $request) { - // - } + $post = new Post; - /** - * Display the specified resource. - * - * @param \App\Post $post - * @return \Illuminate\Http\Response - */ - public function show(Post $post) - { - // + $post->poster_id = $request->user_id; + $post->content = $request->content; + $post->thread_id = $request->thread_id; + + $post->save(); } /** @@ -57,7 +54,7 @@ class PostController extends Controller */ public function edit(Post $post) { - // + return view("edit_post")->withPost($post); } /** @@ -69,7 +66,9 @@ class PostController extends Controller */ public function update(Request $request, Post $post) { - // + $post->content = $request->content; + + $post->save(); } /** diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 137d3d2..1a97dc3 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -24,7 +24,7 @@ class TagController extends Controller */ public function create() { - // + } /** diff --git a/app/Http/Controllers/ThreadController.php b/app/Http/Controllers/ThreadController.php index 67bcbb8..659012c 100644 --- a/app/Http/Controllers/ThreadController.php +++ b/app/Http/Controllers/ThreadController.php @@ -48,11 +48,13 @@ class ThreadController extends Controller /** * Display the specified resource. * - * @param \App\Thread $thread + * @param integer $id + * - A thread ID * @return \Illuminate\Http\Response */ - public function show(Thread $thread) + public function show(integer $id) { + $thread = ThreadsCollection(Thread::find($id)->with("posts")->get()); return view("thread_view")->withThread($thread); } @@ -64,7 +66,7 @@ class ThreadController extends Controller */ public function edit(Thread $thread) { - // + return view("edit")->withThread($thread); } /** @@ -76,7 +78,8 @@ class ThreadController extends Controller */ public function update(Request $request, Thread $thread) { - // + $thread->thread_title = $request->thread_title; + $thread->save(); } /** diff --git a/app/Http/Resources/PostCollection.php b/app/Http/Resources/PostCollection.php new file mode 100644 index 0000000..5343616 --- /dev/null +++ b/app/Http/Resources/PostCollection.php @@ -0,0 +1,21 @@ + $this->$collection + ]; + } +} diff --git a/app/Http/Resources/TagCollection.php b/app/Http/Resources/TagCollection.php new file mode 100644 index 0000000..cf199ce --- /dev/null +++ b/app/Http/Resources/TagCollection.php @@ -0,0 +1,21 @@ + $this->$collection + ]; + } +} diff --git a/app/Http/Resources/ThreadsCollection.php b/app/Http/Resources/ThreadsCollection.php index 4de9ef9..421c1f5 100644 --- a/app/Http/Resources/ThreadsCollection.php +++ b/app/Http/Resources/ThreadsCollection.php @@ -19,6 +19,9 @@ class ThreadsCollection extends ResourceCollection ]; } + /** + * Deprecated, kept for posterity. + */ public function getCreators() { foreach($this->collection as &$t) { $creator = $t->creator; diff --git a/app/Thread.php b/app/Thread.php index 70cdd8d..5d7c0d3 100644 --- a/app/Thread.php +++ b/app/Thread.php @@ -6,8 +6,6 @@ use Illuminate\Database\Eloquent\Model; class Thread extends Model { - private $creator_name; - /** * Get the creator of the thread. */ @@ -21,4 +19,11 @@ class Thread extends Model public function tags() { return $this->belongsToMany('App\Tag'); } + + /** + * Get the posts for the thread. + */ + public function posts() { + return $this->hasMany('App\Post'); + } }