How beyondcode/laravel-comments works
This Laravel package adds polymorphic, nestable comments to Eloquent models. An application model using HasComments creates a comment, optionally on behalf of a user; the user’s Commentator policy determines its initial approval state. Comments can then be retrieved, filtered, approved, nested, or deleted, with add/delete events dispatched by the comment model. Laravel’s Eloquent database is the persistence layer, and the service provider exposes configuration and a migration for host applications. Relationships reflect the shown trait/model calls and documented capabilities; the migration’s schema was not sampled.
Main entry points: Comment.php Comment model · HasComments.php Create and retrieve · create_comments_table.php.stub Comments table · CommentsServiceProvider.php Service provider
Components 10
Comment API
- Commentable models
src/Traits/HasComments.php - Create and retrieve
src/Traits/HasComments.php - Approval policy
src/Contracts/Commentator.php
Comment lifecycle
- Comment model
src/Comment.php - Comments table
database/migrations/create_comments_table.php.stub - Comment added event
src/Events/CommentAdded.php - Comment deleted event
src/Events/CommentDeleted.php
Laravel setup
- Service provider
src/CommentsServiceProvider.php - Package configuration
config/config.php
Other components
- Host application
Connections 11
- Host application → Commentable models: adds trait
README.md - Commentable models → Create and retrieve: exposes
src/Traits/HasComments.php - Create and retrieve → Approval policy: checks approval
src/Traits/HasComments.php - Create and retrieve → Comment model: creates and saves
src/Traits/HasComments.php - Create and retrieve → Comments table: persists via Eloquent
- Comment model → Create and retrieve: supports nested replies
README.md - Comment model → Comments table: stores comment state
- Comment model → Comment added event: dispatches on create
src/Comment.php - Comment model → Comment deleted event: dispatches on delete
src/Comment.php - Service provider → Package configuration: merges config
src/CommentsServiceProvider.php - Service provider → Comments table: publishes migration
src/CommentsServiceProvider.php