sagor-roy/comments
Composer 安装命令:
composer require sagor-roy/comments
包简介
Simple comment system for Laravel 13 with AJAX support
README 文档
README
A simple, lightweight comment system for Laravel 13 with AJAX support.
Requirements
- PHP 8.3+
- Laravel 13.x
Installation
1. Install via Composer
composer require sagor-roy/comments
2. Publish Assets
# Publish all assets php artisan vendor:publish --provider="SagorRoy\Comments\CommentServiceProvider" # Or individually: php artisan vendor:publish --tag=comments-migrations php artisan vendor:publish --tag=comments-config php artisan vendor:publish --tag=comments-views php artisan vendor:publish --tag=comments-assets
3. Run Migrations
php artisan migrate
Usage
1. Make Model Commentable
Add the Commentable trait to any model you want to make commentable:
// app/Models/Article.php <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use SagorRoy\Comments\Traits\Commentable; class Article extends Model { use Commentable; }
2. Display Comments in View
In your Blade template, use the @comments directive:
{{-- resources/views/articles/show.blade.php --}} <article> <h1>{{ $article->title }}</h1> <p>{{ $article->content }}</p> @comments($article) </article>
3. Include CSS
Add the CSS to your layout:
<link rel="stylesheet" href="{{ asset('vendor/comments/comments.css') }}">
4. Include JavaScript
Add the JavaScript to your layout:
<script src="{{ asset('vendor/comments/comments.js') }}"></script>
Configuration
Publish the config file and customize:
php artisan vendor:publish --tag=comments-config
Then edit config/comments.php:
return [ 'max_length' => env('COMMENTS_MAX_LENGTH', 1000), 'allow_guest_replies' => env('COMMENTS_ALLOW_GUEST_REPLIES', true), 'per_page' => env('COMMENTS_PER_PAGE', 15), 'guest_name_required' => env('COMMENTS_GUEST_NAME_REQUIRED', true), 'guest_name_max_length' => env('COMMENTS_GUEST_NAME_MAX', 100), 'user_model' => env('COMMENTS_USER_MODEL', \App\Models\User::class), ];
Environment Variables
Add to your .env file:
COMMENTS_MAX_LENGTH=1000 COMMENTS_ALLOW_GUEST_REPLIES=true COMMENTS_PER_PAGE=15 COMMENTS_GUEST_NAME_REQUIRED=true COMMENTS_GUEST_NAME_MAX=100 COMMENTS_USER_MODEL=App\Models\User
Features
Commentable Models
Any Eloquent model can have comments by adding the Commentable trait.
Nested Comments
Supports 1 level of nested replies. Replies to replies are not allowed.
Guest Comments
Guests can leave comments with just their name. Authenticated users have their name auto-filled.
AJAX Submission
Forms submit via AJAX for better user experience.
Customizable Views
Publish and customize the Blade views to match your design.
Customizing Views
php artisan vendor:publish --tag=comments-views
Views will be copied to resources/views/vendor/comments/.
Security
- CSRF protection enabled
- XSS sanitization via Laravel's default escaping
- User can only delete their own comments
- Configurable max comment length
License
MIT License
sagor-roy/comments 适用场景与选型建议
sagor-roy/comments 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「comments」 「laravel」 「laravel13」 「comment-system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sagor-roy/comments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sagor-roy/comments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sagor-roy/comments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Integerate Symfony Workflow component into Laravel.
Twig extension for Timber which outputs HTML comments before and after the `include` tag
Laravel comment system
Comments system for your Laravel application. Features: can be used to comment on any model, HTML filter customization (HTMLPurifier), API, comment rating, replies, events, auth rules ...
WordPress plugin to force comments to go through the more liberal post HTML filters, rather than the restrictive comment filters.
Minify your blade views, html, css and obfuscate js files on the fly. Lightweight minifier for your Laravel project. Laravel 13 compatible version.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-13