Add post comments with moderation plus view/like interaction endpoints
Deploy Backend / deploy (push) Successful in 2m41s

- blog_comments table + Comment model/factory; comments attach to the post,
  public list shows approved rows only, public submission starts unapproved
- Admin moderation API: list/filter, approve, delete comments
- Public POST posts/{slug}/view and posts/{slug}/like toggle counters
- Route groups: comments throttled like the contact form, interactions at
  60/min; comments resource exposed to the generic admin list
This commit is contained in:
Parsa Aghayi committed 2026-10-02 11:06:06 -04:00
1 parent fbacb0c9a1
commit e98807da05
11 files changed
+497

No files matched your search

+27
View File
@@ -1,10 +1,13 @@
<?php
use App\Http\Controllers\Api\Admin\AdminResourceController;
use App\Http\Controllers\Api\Admin\CommentAdminController;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\Blog\CategoryController;
use App\Http\Controllers\Api\Blog\CommentController;
use App\Http\Controllers\Api\Blog\HomeController;
use App\Http\Controllers\Api\Blog\PostController;
use App\Http\Controllers\Api\Blog\PostInteractionController;
use App\Http\Controllers\Api\Blog\TagController;
use App\Http\Controllers\Api\ContactMessageController;
use App\Http\Controllers\Api\Website\AboutMeController;
@@ -57,6 +60,7 @@ Route::middleware('throttle:60,1')->group(function () {
Route::get('posts', [PostController::class, 'index']);
Route::get('posts/{slug}', [PostController::class, 'show']);
Route::get('posts/{slug}/comments', [CommentController::class, 'index']);
Route::get('categories', [CategoryController::class, 'index']);
Route::get('categories/{id}', [CategoryController::class, 'show']);
@@ -80,6 +84,25 @@ Route::middleware('throttle:60,1')->group(function () {
Route::post('contact', [ContactMessageController::class, 'store'])
->middleware('throttle:5,1');
/*
|--------------------------------------------------------------------------
| Public blog interactions
|--------------------------------------------------------------------------
| Anonymous but mutating, so each endpoint is throttled: comment submission
| is slow like the contact form, view/like counters are faster because they
| are single-column increments triggered once per page load.
*/
Route::middleware('throttle:60,1')->group(function () {
Route::prefix('blog')->group(function () {
Route::post('posts/{slug}/view', [PostInteractionController::class, 'view']);
Route::post('posts/{slug}/like', [PostInteractionController::class, 'like']);
});
});
Route::post('blog/posts/{slug}/comments', [CommentController::class, 'store'])
->middleware('throttle:5,1');
/*
|--------------------------------------------------------------------------
| Admin write API
@@ -105,6 +128,10 @@ Route::middleware(['auth:sanctum', 'admin', 'throttle:30,1'])->group(function ()
Route::put('posts/{id}', [PostController::class, 'update']);
Route::delete('posts/{id}', [PostController::class, 'destroy']);
Route::get('comments', [CommentAdminController::class, 'index']);
Route::put('comments/{id}', [CommentAdminController::class, 'update']);
Route::delete('comments/{id}', [CommentAdminController::class, 'destroy']);
Route::post('categories', [CategoryController::class, 'store']);
Route::put('categories/{id}', [CategoryController::class, 'update']);
Route::delete('categories/{id}', [CategoryController::class, 'destroy']);