You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB
PHTML

6 years ago
<?php
namespace App\Http\Controllers;
use App\Post;
use App\Http\Resources\PostCollection;
6 years ago
use Illuminate\Http\Request;
class PostController extends Controller
{
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Thread $post)
6 years ago
{
return view("create_post")->withThread($post);
6 years ago
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Post $post
* @return \Illuminate\Http\Response
*/
public function edit(Post $post)
{
return view("edit_post")->withPost($post);
}
/**
* Show the posts for a certain thread.
*
* @param int $thread
*/
public function show(int $thread_id) {
$posts = new PostCollection(Post::with("poster")->get()->where("thread_id", $thread_id));
//dd($posts);
return $posts;
}
6 years ago
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post;
6 years ago
$post->poster_id = $request->user_id;
$post->content = $request->content;
$post->thread_id = $request->thread_id;
$post->save();
6 years ago
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Post $post
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Post $post)
{
$post->content = $request->content;
$post->save();
6 years ago
}
/**
* Remove the specified resource from storage.
*
* @param int $id
6 years ago
* @return \Illuminate\Http\Response
*/
public function destroy(int $id)
6 years ago
{
Post::find($id)->delete();
6 years ago
}
}