Download the PHP package newway-solutions/laravel-comments without Composer
On this page you can find all versions of the php package newway-solutions/laravel-comments. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download newway-solutions/laravel-comments
More information about newway-solutions/laravel-comments
Files in newway-solutions/laravel-comments
Package laravel-comments
Short Description Add comments to your Laravel application
License MIT
Homepage https://github.com/New-Way-Solutions-MM/laravel-comment-package
Informations about the package laravel-comments
Laravel Comments
A Laravel package that provides a simple and flexible commenting system for your Laravel application. Add comments to any Eloquent model with support for nested replies, comment approval, and event-driven notifications.
Features
- ๐ฌ Add comments to any Eloquent model
- ๐ Nested comments and replies support
- โ Comment approval system
- ๐ฏ Polymorphic relationships
- ๐ก Event-driven architecture
- ๐ Flexible user authentication
- ๐งช Comprehensive test coverage
- ๐ฆ Easy installation and configuration
Requirements
- PHP 8.1 or higher
- Laravel 10.0, 11.0, or 12.0
Installation
You can install the package via composer:
Publish and Run Migrations
Publish the migration and run it:
Publish Configuration (Optional)
You can publish the config file with:
This will publish a config file to config/comments.php where you can customize the package behavior.
Configuration
Basic Configuration
The configuration file allows you to customize several aspects:
Usage
Preparing Your Models
Making Models Commentable
To allow a model to have comments, use the HasComments trait:
Making Users Able to Comment
For users to be able to comment, implement the Commentator contract and use the CanComment trait:
Basic Usage
Adding Comments
Retrieving Comments
Working with Nested Replies
Comment Management
Approving and Disapproving Comments
Deleting Comments
Advanced Usage
Using Query Scopes
Accessing Comment Relationships
Events
The package dispatches events when comments are created or deleted:
CommentAdded Event
CommentDeleted Event
Register your listeners in EventServiceProvider:
API Reference
HasComments Trait Methods
| Method | Description |
|---|---|
comments() |
Returns all comments for the model |
comment($comment) |
Add a comment as the authenticated user |
commentAsUser($user, $comment) |
Add a comment as a specific user |
replyToComment($parentComment, $comment, $user = null) |
Reply to an existing comment |
Comment Model Methods
| Method | Description |
|---|---|
approve() |
Approve the comment |
disapprove() |
Disapprove the comment |
commentable() |
Get the model that was commented on |
commentator() |
Get the user who made the comment |
parent() |
Get the parent comment (for replies) |
replies() |
Get all replies to this comment |
Query Scopes
| Scope | Description |
|---|---|
approved() |
Get only approved comments |
Database Structure
The package creates a comments table with the following structure:
Examples
Complete Example: Blog with Comments
Blade Template Example
Testing
Run the tests with:
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Moe Wai Yan
- Phone Htut Khaung
- All Contributors
License
The MIT License (MIT). Please see License File for more information.