Files
2025-02-16 21:11:07 +02:00

58 lines
1.3 KiB
PHP

<?php
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)
{
}
}