定制 fperdomo/laravel-comments 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fperdomo/laravel-comments

最新稳定版本:v0.0.2

Composer 安装命令:

composer require fperdomo/laravel-comments

包简介

Add comments to your laravel model

README 文档

README

A lightweight Laravel package to add comments and replies to any Eloquent model using a simple use HasComments trait.

✨ Features

  • Add comments to any model
  • Nested comment replies
  • Retrieve all comments or threaded replies
  • Soft deletes supported
  • Automatically deletes child comments when parent is removed
  • Clean and extensible

📦 Installation

composer require fperdomo/laravel-comments

Setup

  1. Publish Migrations (optional if auto-discovered)
php artisan migrate
  1. Use the HasComments trait in any model:
use Fperdomo\Comments\Traits\HasComments;

class Post extends Model
{
    use HasComments;
}

Usage

➕ Add a Comment

$post = Post::find(1);
$comment = $post->comment("I've got a feeling...");

🧑‍💻 Comment as User

$post->commentAsUser("This is great!", auth()->user()->id);

Reply to a Comment

$reply = $comment->reply("Same here!");

Retrieve Comments

$comments = $post->comments;              // All comments (including replies)
$topLevel = $post->comments()->whereNull('parent_id')->get(); // Only top-level
$replies = $comment->replies;             // Replies to a comment

Update a Comment

$comment->update([
    'original_text' => 'Updated comment text',
]);

Delete a Comment

$comment->delete(); // Will also delete nested replies

📘 License

This package is open-sourced under the MIT license.

🙌 Credits

Developed by Fermin Perdomo

Inspired by Laravel's elegant approach to polymorphic relationships.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-25