https://github.com/jkm96/comment-buddy
A plug-and-play Laravel Livewire comment system for your blog posts.
https://github.com/jkm96/comment-buddy
blog comment-buddy comment-system comments laravel livewire
Last synced: about 2 months ago
JSON representation
A plug-and-play Laravel Livewire comment system for your blog posts.
- Host: GitHub
- URL: https://github.com/jkm96/comment-buddy
- Owner: jkm96
- License: mit
- Created: 2025-06-06T08:04:58.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-06T13:46:38.000Z (about 1 year ago)
- Last Synced: 2025-06-17T13:03:56.865Z (about 1 year ago)
- Topics: blog, comment-buddy, comment-system, comments, laravel, livewire
- Language: PHP
- Homepage: https://commentbuddy.mblog.co.ke
- Size: 33.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


# Comment Buddy
**Comment Buddy** is a plug-and-play Laravel Livewire comment system for posts. It supports nested replies and optional success toasts for a seamless commenting experience.
---
## Installation
1.In your Laravel project’s composer.json, add this:
```php
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jkm96/comment-buddy"
}
]
```
2.Then run:
```bash
composer require jkm96/comment-buddy
```
3.Publish the configuration file:
```bash
php artisan vendor:publish --tag=comment-buddy-config
```
This command creates the configuration file at `config/comment-buddy.php`.
4.Publish the views:
```bash
php artisan vendor:publish --tag=comment-buddy-views
```
This command will copy all your views into the user’s project under:
```php
resources/views/vendor/comment-buddy/
```
5.Run the migrations to create the necessary database tables:
```bash
php artisan migrate
```
---
## Configuration
Edit the configuration file `config/comment-buddy.php` to customize the package behavior:
```php
return [
'comment_model' => Comment::class,
'show_message' => true,
];
```
- `comment_model` — The Eloquent model used to store comments.
- `show_message` — Enable or disable toast messages on successful actions.
---
## Usage
To include the comment system in a Blade view (e.g., on a post detail page), add:
```blade
```
Make sure your post model has an `id` and a relationship to comments.
````php
public function comments()
{
return $this->hasMany(Comment::class)->whereNull('parent_id');
}
````
If `show_message` is enabled, listen for toast messages with Livewire:
```html
Livewire.on('toast-message', details => {
alert(details.message); // Replace this with your own toast notification logic
});
```
---
## How It Works
- `comment-section` — renders the entire comment thread along with the comment form.
- `comment-form` — handles submitting new comments and replies.
- `comment-thread` — renders nested replies recursively.
- Uses Livewire for reactive, dynamic UI updates.
- Comments are saved via the model defined in `comment_model` configuration.
---
## Service Provider
Comment Buddy auto-registers Livewire components and loads resources through its service provider:
```php
Livewire::component('comment-form', CommentForm::class);
Livewire::component('comment-section', CommentSection::class);
Livewire::component('comment-thread', CommentThread::class);
```
It also loads views, migrations, and merges the configuration from:
```
__DIR__ . '/../config/comment-buddy.php'
```
---
## Authentication
User authentication is required to post comments. If a user is not logged in, the comment form will not be displayed.
**Note:** Guest commenting is not supported out of the box.
---
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Feel free to customize and extend Comment Buddy to fit your project's needs!