Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
feat: add PostCommentController with CRUD + reactions routes
Paulo Castellanoe3d14256e066
diff --git a/app/Http/Controllers/App/PostCommentController.php b/app/Http/Controllers/App/PostCommentController.phpnew file mode 100644index 000000000..1ae35a720--- /dev/null+++ b/app/Http/Controllers/App/PostCommentController.php@@ -0,0 +1,108 @@+<?php++declare(strict_types=1);++namespace App\Http\Controllers\App;++use App\Events\PostCommentCreated;+use App\Models\Post;+use App\Models\PostComment;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+use Symfony\Component\HttpFoundation\Response;++class PostCommentController extends Controller+{+ public function index(Request $request, Post $post): JsonResponse+ {+ $workspace = $request->user()->currentWorkspace;++ if ($post->workspace_id !== $workspace->id) {+ abort(Response::HTTP_FORBIDDEN);+ }++ $comments = $post->comments()+ ->whereNull('parent_id')+ ->with(['user', 'replies.user'])+ ->latest()+ ->paginate(config('app.pagination.default'));++ return response()->json($comments);+ }++ public function store(Request $request, Post $post): JsonResponse+ {+ $workspace = $request->user()->currentWorkspace;++ if ($post->workspace_id !== $workspace->id) {+ abort(Response::HTTP_FORBIDDEN);+ }++ $validated = $request->validate([+ 'body' => ['required', 'string', 'max:2000'],+ 'parent_id' => ['nullable', 'uuid', 'exists:post_comments,id'],+ ]);++ if (data_get($validated, 'parent_id')) {+ $parent = PostComment::find(data_get($validated, 'parent_id'));+ if ($parent && $parent->parent_id !== null) {+ abort(Response::HTTP_UNPROCESSABLE_ENTITY, 'Cannot reply to a reply.');+ }+ }++ $comment = $post->comments()->create([+ 'user_id' => $request->user()->id,+ 'parent_id' => data_get($validated, 'parent_id'),+ 'body' => data_get($validated, 'body'),+ ]);++ $comment->load('user');++ PostCommentCreated::dispatch($comment);++ return response()->json($comment, Response::HTTP_CREATED);+ }++ public function update(Request $request, Post $post, PostComment $comment): JsonResponse+ {+ if ($comment->user_id !== $request->user()->id) {+ abort(Response::HTTP_FORBIDDEN);+ }++ $validated = $request->validate([+ 'body' => ['required', 'string', 'max:2000'],+ ]);++ $comment->update(['body' => data_get($validated, 'body')]);++ return response()->json($comment);+ }++ public function destroy(Request $request, Post $post, PostComment $comment): JsonResponse+ {+ if ($comment->user_id !== $request->user()->id) {+ abort(Response::HTTP_FORBIDDEN);+ }++ $comment->delete();++ return response()->json(null, Response::HTTP_NO_CONTENT);+ }++ public function react(Request $request, Post $post, PostComment $comment): JsonResponse+ {+ $workspace = $request->user()->currentWorkspace;++ if ($post->workspace_id !== $workspace->id) {+ abort(Response::HTTP_FORBIDDEN);+ }++ $validated = $request->validate([+ 'emoji' => ['required', 'string', 'max:10'],+ ]);++ $comment->addReaction($request->user()->id, data_get($validated, 'emoji'));++ return response()->json($comment->fresh());+ }+}diff --git a/lang/en/comments.php b/lang/en/comments.phpnew file mode 100644index 000000000..b450af7ad--- /dev/null+++ b/lang/en/comments.php@@ -0,0 +1,16 @@+<?php++return [+ 'placeholder' => 'Write a comment...',+ 'reply_placeholder' => 'Write a reply...',+ 'reply' => 'Reply',+ 'edit' => 'Edit',+ 'delete' => 'Delete',+ 'edited' => 'edited',+ 'save' => 'Save',+ 'cancel' => 'Cancel',+ 'send' => 'Send',+ 'replying_to' => 'Replying to :name',+ 'empty' => 'No comments yet. Start the conversation.',+ 'load_more' => 'Load older comments',+];diff --git a/routes/app.php b/routes/app.phpindex ff42130ee..9777041b9 100644--- a/routes/app.php+++ b/routes/app.php@@ -10,6 +10,7 @@ use App\Http\Controllers\App\GiphyController;use App\Http\Controllers\App\MediaController;use App\Http\Controllers\App\NotificationController;use App\Http\Controllers\App\OnboardingController;+use App\Http\Controllers\App\PostCommentController;use App\Http\Controllers\App\PostController;use App\Http\Controllers\App\Settings\AccountController;use App\Http\Controllers\App\Settings\NotificationPreferenceController;@@ -141,6 +142,13 @@ Route::middleware(['auth', 'verified', 'subscribed', EnsureUserSetupIsComplete::Route::put('posts/{post}', [PostController::class, 'update'])->name('app.posts.update');Route::delete('posts/{post}', [PostController::class, 'destroy'])->name('app.posts.destroy');+ // Post Comments+ Route::get('posts/{post}/comments', [PostCommentController::class, 'index'])->name('app.posts.comments.index');+ Route::post('posts/{post}/comments', [PostCommentController::class, 'store'])->name('app.posts.comments.store');+ Route::put('posts/{post}/comments/{comment}', [PostCommentController::class, 'update'])->name('app.posts.comments.update');+ Route::delete('posts/{post}/comments/{comment}', [PostCommentController::class, 'destroy'])->name('app.posts.comments.destroy');+ Route::post('posts/{post}/comments/{comment}/react', [PostCommentController::class, 'react'])->name('app.posts.comments.react');+// MediaRoute::post('medias', [MediaController::class, 'store'])->name('app.medias.store');Route::post('medias/chunked', [MediaController::class, 'storeChunked'])->name('app.medias.store-chunked');