PHPackages                             sohrab-az/laravel-comment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sohrab-az/laravel-comment

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sohrab-az/laravel-comment
=========================

A flexible comment package for Laravel

1.0.0(1mo ago)00MITPHP

Since May 5Pushed 1mo agoCompare

[ Source](https://github.com/sohrab-az/laravel-comment)[ Packagist](https://packagist.org/packages/sohrab-az/laravel-comment)[ RSS](/packages/sohrab-az-laravel-comment/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

📦 Laravel Comment Package
=========================

[](#-laravel-comment-package)

A lightweight and flexible comment system for Laravel with support for nested replies, polymorphic relations, and status workflow.

✨ Features
----------

[](#-features)

- Nested comments (threaded replies)
- Polymorphic support (commentable)
- User or guest commenting
- Status workflow (pending, approved, rejected)
- Configurable max reply depth
- Clean service layer (CommentManager, CommentQuery)
- Fluent query builder for comments
- Simple trait integration

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require sohrab-azinfar/comment
```

⚙️ Publish Config &amp; Migrations

```
php artisan vendor:publish --tag=comment-config
php artisan migrate
```

⚙️ Configuration

`config/comment.php`

```
return [
    'default_status' => \SohrabAzinfar\Comment\Enums\CommentStatusEnum::Pending->value,

    // Maximum depth of nested replies
    'depth' => 5,
];
```

🧠 Usage
-------

[](#-usage)

Add Trait to your Model

```
use SohrabAzinfar\Comment\Traits\HasComments;

class Post extends Model
{
    use HasComments;
}
```

💬 Creating Comments
-------------------

[](#-creating-comments)

### Create comment

[](#create-comment)

```
$post->addComment(
    body: 'This is a comment',
    author: auth()->user()
);
```

### Guest comment

[](#guest-comment)

```
$post->addComment(
    body: 'Hello world',
    author: null,
    guest: [
        'name' => 'John',
        'email' => 'john@example.com'
    ]
);
```

🔁 Reply to a Comment
--------------------

[](#-reply-to-a-comment)

```
$post->replyTo($comment, 'This is a reply', auth()->user());
```

🔍 Query Comments
----------------

[](#-query-comments)

```
$comments = $post->queryComment()
    ->approved()
    ->roots()
    ->withReplies()
    ->get();
```

### Pagination

[](#pagination)

```
$comments = $post->queryComment()->paginate(10);
```

🧾 Comment Status
----------------

[](#-comment-status)

```
use SohrabAzinfar\Comment\Enums\CommentStatusEnum;

CommentStatusEnum::Pending;
CommentStatusEnum::Approved;
CommentStatusEnum::Rejected;
```

⚙️ Approve / Reject
-------------------

[](#️-approve--reject)

```
$post->approve($comment);
$post->reject($comment);
```

🧹 Delete Comment (with descendants)
-----------------------------------

[](#-delete-comment-with-descendants)

```
$post->deleteComment($comment);
```

🧱 Database Structure
--------------------

[](#-database-structure)

The package creates a `comments` table with:

- Polymorphic relation (`commentable`)
- Optional author morph (`author`)
- Nested set support (tree structure)
- Status management
- Soft-style timestamps

🧠 Architecture
--------------

[](#-architecture)

- `CommentManager` → write operations (create, reply, approve, reject, delete)
- `CommentQuery` → read/query layer
- `HasComments` → model integration layer
- `Comment` → core entity model
- `NestedSet` → tree handling (Kalnoy package)

🚀 Example
---------

[](#-example)

```
$post = Post::find(1);

$comment = $post->addComment('Nice post!', auth()->user());

$post->replyTo($comment, 'Thanks!');
```

📌 Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10+

📄 License
---------

[](#-license)

MIT License. Use freely in personal and commercial projects.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance93

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

35d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54e2e41c158ddc0f29395d4c4e3b16d2e4ba8e0adcc8eca90f092c58d7fde315?d=identicon)[sohrab-az](/maintainers/sohrab-az)

---

Top Contributors

[![sohrab-az](https://avatars.githubusercontent.com/u/76838208?v=4)](https://github.com/sohrab-az "sohrab-az (2 commits)")

### Embed Badge

![Health badge](/badges/sohrab-az-laravel-comment/health.svg)

```
[![Health](https://phpackages.com/badges/sohrab-az-laravel-comment/health.svg)](https://phpackages.com/packages/sohrab-az-laravel-comment)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.1k2.2k](/packages/unopim-unopim)[riari/laravel-forum

A Laravel package providing a solid foundation for building discussion forums

65397.7k3](/packages/riari-laravel-forum)[biostate/filament-menu-builder

An Elegant Menu Builder for FilamentPHP

6422.4k](/packages/biostate-filament-menu-builder)[wsmallnews/filament-nestedset

Filament nestedset tree builder powered by kalnoy/nestedset with Filament v4 and v5 support

196.5k14](/packages/wsmallnews-filament-nestedset)[novius/laravel-nova-order-nestedset-field

A Laravel Nova field that make your resources orderable

2391.9k2](/packages/novius-laravel-nova-order-nestedset-field)[phoenix-lib/nova-nested-tree-attach-many

Nova vue-tree-select field for management nested category relations.

3590.1k](/packages/phoenix-lib-nova-nested-tree-attach-many)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
