rizwan3d/comment-system
Composer 安装命令:
composer require rizwan3d/comment-system
包简介
A robust and flexible comment system for Laravel applications.
README 文档
README
Rizwan3d/CommentSystem
This Laravel package provides a robust and flexible comment system for your applications. It enables you to seamlessly integrate commenting functionality into your models, allowing users to engage in discussions and leave feedback.
Installation
-
Add the package to your project's
composer.jsonfile:"require": { "rizwan3d/comment-system": "^1.0" }
-
Run Composer to install the package:
composer update
-
Register the service provider:
Open your
config/app.phpfile and add the following line to theprovidersarray:Rizwan3d\CommentSystem\Providers\CommentSystemServiceProvider::class,
Usage
-
Apply the
Commentabletrait to your models:The
Commentabletrait provides methods for adding and retrieving comments associated with your models. Add the following line at the top of your model class:use Rizwan3d\CommentSystem\Traits\Commentable;
-
Adding Comments:
Use the
addCommentmethod to add a new comment to your model instance:$model->addComment($content);
- Replace
$contentwith the actual comment text.
- Replace
-
Retrieving Comments:
The
commentsmethod returns a collection of comments associated with your model instance:$comments = $model->comments;
This method automatically retrieves comments with nested replies using eager loading.
-
Model Relationships (Optional):
The package supports defining relationships between comments. You can add the
parent_idfield to yourCommentmodel migration and define the following relationships:parent: This belongs-to relationship allows you to link comments to their parent comment.comments: This has-many relationship retrieves child comments of a specific comment.
Example Usage
use App\Post; // Replace with your model class $post = Post::find(1); $comment = $post->addComment('This post is great!'); $childComment = $comment->addComment('I agree!'); $allComments = $post->comments; // Includes $comment and $childComment
Features
- Integrates seamlessly with your Laravel models.
- Allows users to add comments to any model.
- Supports nested replies (optional).
- Provides methods for adding, retrieving, and managing comments.
View Example
comment.blade.php
<ol>
@foreach ($comments as $comment)
<li>{{$comment->content}}</li>
@include('comment',['comments' => $comment->comments])
@endforeach
</ol>
Contributing
We welcome contributions to this package! Please refer to the contribution guidelines for more information.
License
This package is licensed under the MIT License. See the LICENSE file for details.
Additional Notes
- Consider adding comments and explanations within the code for better readability.
- Feel free to extend the functionality of this package based on your specific requirements.
rizwan3d/comment-system 适用场景与选型建议
rizwan3d/comment-system 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「comments」 「laravel」 「discussion」 「feedback」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rizwan3d/comment-system 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rizwan3d/comment-system 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rizwan3d/comment-system 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Twig extension for Timber which outputs HTML comments before and after the `include` tag
Make posts hidden for visitors.
Add custom fields to discussions
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 ...
Output of discussions lists in form of cards
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-16