Pros:
Post, Article, Product), promoting reuse across domains.parent_id) enables threaded discussions, a common requirement.Cons:
title (nullable) and body; lacks support for rich text, attachments, or complex rules.CommentController).comments table, migrations must be merged or renamed.Thread, Reply) may require trait overrides.composer require alibayat/laravel-commentable.php artisan vendor:publish --provider="AliBayat\LaravelCommentable\CommentableServiceProvider".deleted_at if using soft deletes).Commentable trait to target models (e.g., Post, Article).use AliBayat\LaravelCommentable\Commentable;
class Post extends Model {
use Commentable;
}
post/{post}/comments).public function store(Request $request, Post $post) {
$comment = $post->comment($request->validate([
'body' => 'required|string',
]), auth()->user());
return response()->json($comment);
}
createComment helper methods).bigIncrements for id in PostgreSQL).comments table name (e.g., spatie/laravel-commentable).comment(), replies()).Comment to include is_approved").commentable_id, parent_id, and created_at.with() for eager loading or implement lazy-loading to avoid N+1.How can I help you explore Laravel packages today?