nirajan / comment
A Laravel package for handling comments
1.0.1
2026-03-18 08:36 UTC
Requires
- php: ^8.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- orchestra/testbench: ^7.0
- phpunit/phpunit: ^10.0
README
A simple, reusable Laravel package to add commenting functionality to any Eloquent model with minimal setup.
Features
- Polymorphic Support: Add comments to any model (Posts, Products, etc.) using a single Trait.
- Blade Components: Includes ready-to-use components for comment forms and lists.
- Admin Dashboard: Built-in management interface at
/AdminActivity/comments. - Security: Integrated ReCAPTCHA validation support.
- Moderation: Optional comment approval system.
- Customizable: Easily configurable middleware, layouts, and routes.
Installation
1. Require the package via Composer
composer require nirajan/comment
2. Publish Configuration and Migrations
php artisan vendor:publish --provider="Nirajan\Comment\CommentServiceProvider"
3. Run Migrations
php artisan migrate
Configuration
After publishing, you can find the configuration file at config/comment.php.
return [ 'admin_middleware' => ['web', 'admin'], 'recaptcha_site_key' => env('RECAPTCHA_SITE_KEY'), 'recaptcha_secret_key'=> env('RECAPTCHA_SECRET_KEY'), 'admin_url_prefix' => 'AdminActivity', 'admin_layout' => 'backend.layouts.master', 'need_approval' => false, 'post_route' => [ 'name' => 'posts.detail', 'param' => 'id', 'callback' => null, ], ];
Usage
1. Prepare your Model
Add the HasComments trait to any model you want to allow comments on.
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Nirajan\Comment\Traits\HasComments; class Post extends Model { use HasComments; }
2. Add Blade Components
Insert the following components into your views (e.g., show.blade.php).
<x-comment::comment-form :model="$post" /> <x-comment::comment-list :model="$post" />
Admin Dashboard
You can manage, delete, and approve comments through the built-in dashboard:
your-domain.com/AdminActivity/comments
Note: Ensure your admin_layout in the config file matches your actual admin theme layout.
License
The MIT License (MIT). Please see the License File for more information.
Contributing
Feel free to submit issues or pull requests to improve this package.