This commit is contained in:
2025-02-16 21:11:07 +02:00
parent 87bbfc33d3
commit e8d7e6a1c4
253 changed files with 3879 additions and 72 deletions
+47 -1
View File
@@ -3,9 +3,55 @@
namespace App\Http\Controllers\Forum;
use App\Http\Controllers\Controller;
use App\Http\Requests\Forum\PostRequest;
use App\Models\Forum\Post;
use App\Models\Forum\Thread;
use App\Models\Forum\Topic;
use Illuminate\Http\Request;
class PostsController extends Controller
{
//
public function create()
{
// full reply?
}
public function store(PostRequest $request, string $categorySlug, string $threadSlug, string $topicSlug)
{
$thread = Thread::with('category')->where('slug', $threadSlug)->first();
$topic = Topic::where('slug', $topicSlug)->first();
if ($topic->status == Topic::STATUS_CLOSED) {
abort(403);
}
Post::create([
'content' => $request->get('content'),
'user_id' => auth()->user()->id,
'category_id' => $thread->category->id,
'thread_id' => $thread->id,
'topic_id' => $topic->id,
]);
$topic->replies_no = $topic->replies_no+1;
$topic->save();
// redirect back, keep in mind pagination
return redirect()->back()->with('success', 'Reply posted!');
}
public function edit(int $id)
{
}
public function update(PostRequest $request, int $id)
{
}
public function destroy(int $id)
{
}
}
@@ -4,12 +4,76 @@ namespace App\Http\Controllers\Forum;
use App\Http\Controllers\Controller;
use App\Http\Requests\Forum\TopicRequest;
use App\Models\Forum\Category;
use App\Models\Forum\Post;
use App\Models\Forum\Thread;
use App\Models\Forum\Topic;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class TopicsController extends Controller
{
public function create(TopicRequest $request)
public function show(string $categorySlug, string $threadSlug, string $topicSlug)
{
return view('forum.topics.create');
$thread = Thread::with('category')->where('slug', $threadSlug)->first();
$topic = Topic::where('slug', $topicSlug)->first();
$topic->views_no = $topic->views_no+1;
$topic->save();
$posts = Post::with('author')->where('topic_id', $topic->id)->paginate(15);
return view('forum.topics.show', compact('thread', 'topic', 'posts'));
}
public function create(string $categorySlug, string $threadSlug)
{
// check policy
$forumCategories = Category::get();
$forumThreads = Thread::get();
$currentThread = Thread::with('category')->where('slug', $threadSlug)->first();
return view('forum.topics.create', compact('forumCategories', 'forumThreads', 'currentThread'));
}
public function store(TopicRequest $request, string $categorySlug, string $threadSlug)
{
// check policy
$thread = Thread::with('category')->where('slug', $threadSlug)->first();
$topic = Topic::create([
'name' => $request->get('name'),
'slug' => Str::slug($request->get('name')),
'status' => Topic::STATUS_OPEN,
'category_id' => $thread->category->id,
'thread_id' => $thread->id,
'user_id' => auth()->user()->id,
]);
Post::create([
'content' => $request->get('content'),
'user_id' => auth()->user()->id,
'category_id' => $thread->category->id,
'thread_id' => $thread->id,
'topic_id' => $topic->id,
]);
return redirect()->route('forums.thread.topics.show', [$categorySlug, $threadSlug, $topic->slug]);
}
public function edit(string $categorySlug, string $threadSlug, string $topicSlug)
{
// check policy
}
public function update(TopicRequest $request)
{
// check policy
}
public function destroy()
{
// check policy
}
}