PHPackages                             x-laravel/commentable - 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. [Database &amp; ORM](/categories/database)
4. /
5. x-laravel/commentable

ActiveLibrary[Database &amp; ORM](/categories/database)

x-laravel/commentable
=====================

Polymorphic comment system for Laravel Eloquent models with nested comment support.

v1.0.0(2mo ago)111↓100%MITPHPPHP ^8.2CI passing

Since Apr 11Pushed 2mo agoCompare

[ Source](https://github.com/x-laravel/commentable)[ Packagist](https://packagist.org/packages/x-laravel/commentable)[ RSS](/packages/x-laravel-commentable/feed)WikiDiscussions master Synced 1w ago

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

Commentable
===========

[](#commentable)

[![Tests](https://github.com/x-laravel/commentable/actions/workflows/tests.yml/badge.svg)](https://github.com/x-laravel/commentable/actions/workflows/tests.yml)[![PHP](https://camo.githubusercontent.com/187240af044d09d5b14a1d9d9ebdf3f7a993e4c7bc09bdb46b4ba661a891bf5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c7565)](https://www.php.net)[![Laravel](https://camo.githubusercontent.com/42e62a9adb05b6cb16993782fd4b04b64a76be3ff5704d170001885eb70c8448/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313225323025374325323031332d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE.md)

A Laravel package that adds a polymorphic, infinitely nested comment system to any Eloquent model.

How It Works
------------

[](#how-it-works)

- Any model can receive comments via the `Commentable` trait
- Any model can post comments via the `Commenter` trait
- Replies can be nested to any depth
- Replies are lazy-loaded — fetch only what you need, when you need it
- Commenters are optional — anonymous comments are supported

Requirements
------------

[](#requirements)

- PHP ^8.2
- Laravel ^12.0 | ^13.0

Installation
------------

[](#installation)

```
composer require x-laravel/commentable
```

Run the migration:

```
php artisan migrate
```

Setup
-----

[](#setup)

### Receiving comments

[](#receiving-comments)

Add `Commentable` to any model that should receive comments:

```
use Illuminate\Database\Eloquent\Model;
use XLaravel\Commentable\Commentable;

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

### Posting comments

[](#posting-comments)

Add `Commenter` to any model that should be able to post comments:

```
use Illuminate\Database\Eloquent\Model;
use XLaravel\Commentable\Commenter;

class User extends Model
{
    use Commenter;
}
```

Usage
-----

[](#usage)

### Adding a comment

[](#adding-a-comment)

```
// Anonymous
$post->addComment('Great post!');

// With a commenter
$post->addComment('Great post!', $user);

// Via Commenter
$user->comment($post, 'Great post!');
```

### Adding a reply

[](#adding-a-reply)

```
// Via Commentable
$post->addReply($comment, 'I agree!', $user);

// Via Commenter
$user->reply($post, $comment, 'I agree!');
```

> Replies can be added to any comment or reply. There is no depth limit.

### Listing root comments

[](#listing-root-comments)

```
$post->rootComments()->paginate(20);
```

Chain relations as needed:

```
$post->rootComments()->withCount('replies')->with('commenter')->paginate(20);
```

### Listing replies (lazy-load)

[](#listing-replies-lazy-load)

```
$comment->replies()->paginate(10);
```

```
$comment->replies()->withCount('replies')->with('commenter')->paginate(10);
```

### Other relations

[](#other-relations)

```
// All comments on a model (root + replies)
$post->comments()->get();

// All comments posted by a user
$user->comments()->get();

// The parent of a reply
$comment->parent;

// The model a comment belongs to
$comment->commentable;

// Check if a comment is a reply
$comment->isReply(); // true / false
```

### Soft deleting

[](#soft-deleting)

```
$comment->delete();       // soft delete
$comment->restore();      // restore
$comment->forceDelete();  // permanent delete (cascades to replies via FK)
```

> Soft-deleting a parent comment does **not** cascade to its replies. If you want cascade-on-soft-delete behaviour, add a `deleting` event listener to your application.

Suggested API Design
--------------------

[](#suggested-api-design)

```
GET    /posts/{post}/comments           → List root comments (paginated)
POST   /posts/{post}/comments           → Add a comment

GET    /comments/{comment}/replies      → List replies (paginated)
POST   /comments/{comment}/replies      → Add a reply

DELETE /comments/{comment}              → Soft delete a comment

```

Database
--------

[](#database)

```
comments
├── id
├── commentable_type   (polymorphic — Post, Event, etc.)
├── commentable_id
├── commenter_type     (nullable polymorphic — User, Admin, etc.)
├── commenter_id
├── parent_id          (nullable FK → comments.id, cascadeOnDelete)
├── body
├── created_at
├── updated_at
└── deleted_at         (soft delete)

```

Testing
-------

[](#testing)

```
# Build first (once per PHP version)
DOCKER_BUILDKIT=0 docker compose --profile php82 build

# Run tests
docker compose --profile php82 up
docker compose --profile php83 up
docker compose --profile php84 up
docker compose --profile php85 up
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/license/MIT).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bdb64c6c087c331b8bd5906bb1aa7eb06bc83af3654a48ba8ab9da365976651?d=identicon)[X-Adam](/maintainers/X-Adam)

---

Top Contributors

[![x-adam](https://avatars.githubusercontent.com/u/60411758?v=4)](https://github.com/x-adam "x-adam (1 commits)")

---

Tags

laraveleloquentcommentscommentable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/x-laravel-commentable/health.svg)

```
[![Health](https://phpackages.com/badges/x-laravel-commentable/health.svg)](https://phpackages.com/packages/x-laravel-commentable)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M84](/packages/mongodb-laravel-mongodb)[spatie/laravel-sluggable

Generate slugs when saving Eloquent models

1.5k12.4M291](/packages/spatie-laravel-sluggable)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[watson/validating

Eloquent model validating trait.

9743.4M53](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8733.1M23](/packages/yajra-laravel-oci8)

PHPackages © 2026

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