PHPackages                             anil/comments - 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. anil/comments

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

anil/comments
=============

A Laravel package providing a full-featured, framework-agnostic commenting system for any Eloquent model.

v2.0.0(1mo ago)48.2k—0%1MITPHPPHP ^8.2|^8.3|^8.4|^8.5CI passing

Since Apr 19Pushed 1y agoCompare

[ Source](https://github.com/anilkumarthakur60/comments)[ Packagist](https://packagist.org/packages/anil/comments)[ RSS](/packages/anil-comments/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (2)Dependencies (20)Versions (7)Used By (0)

Comments
========

[](#comments)

Comments is a Laravel package. With it you can easily implement native comments for your application.

Overview
--------

[](#overview)

This package can be used to comment on any model you have in your application.

All comments are stored in a single table with a polymorphic relation for content and a polymorphic relation for the user who posted the comment.

### Features

[](#features)

- View comments
- Create comments
- Delete comments
- Edit comments
- Reply to comments
- Authorization rules
- Support localization
- Dispatch events
- Route, Controller, Comment, Migration &amp; View customizations
- Support for non-integer IDs
- Support for multiple User models
- Solved N+1 query problem
- Comment approval (opt-in)
- Guest commenting (opt-in)
- Pagination (opt-in)
- Soft deletes (opt-in)
- Works with custom ID columns
- Optionally load package migrations \[NEW\]
- Configure maximum indentation level \[NEW\]

### Screenshots

[](#screenshots)

Here are a few screenshots.

No comments &amp; guest:

[![](https://camo.githubusercontent.com/264e6915c0bb966e251c87be7fa5f4ad3247db56ea910c4e3f2ec2df13411018/68747470733a2f2f692e696d6775722e636f6d2f3964663458756e2e706e67)](https://camo.githubusercontent.com/264e6915c0bb966e251c87be7fa5f4ad3247db56ea910c4e3f2ec2df13411018/68747470733a2f2f692e696d6775722e636f6d2f3964663458756e2e706e67)

No comments &amp; logged in:

[![](https://camo.githubusercontent.com/0784c78a8430f2b6da145921197ed49726e7141244e42e57a0d4bd2e9202e55d/68747470733a2f2f692e696d6775722e636f6d2f414c49364762522e706e67)](https://camo.githubusercontent.com/0784c78a8430f2b6da145921197ed49726e7141244e42e57a0d4bd2e9202e55d/68747470733a2f2f692e696d6775722e636f6d2f414c49364762522e706e67)

One comment:

[![](https://camo.githubusercontent.com/925fcf402a670fc73a8bdcb6be8ab05ba8270afa272acbacb03b533e5c04d748/68747470733a2f2f692e696d6775722e636f6d2f3977424e6979322e706e67)](https://camo.githubusercontent.com/925fcf402a670fc73a8bdcb6be8ab05ba8270afa272acbacb03b533e5c04d748/68747470733a2f2f692e696d6775722e636f6d2f3977424e6979322e706e67)

One comment edit form:

[![](https://camo.githubusercontent.com/ec9aafbae41358688d2fdecc5b12f4a42c1e900f0384c4aa52e1fd8a396e0128/68747470733a2f2f692e696d6775722e636f6d2f6378446833344f2e706e67)](https://camo.githubusercontent.com/ec9aafbae41358688d2fdecc5b12f4a42c1e900f0384c4aa52e1fd8a396e0128/68747470733a2f2f692e696d6775722e636f6d2f6378446833344f2e706e67)

Two comments from different users:

[![](https://camo.githubusercontent.com/4d4650eb726f4c0571931e080798c6112b956944fc97184610dadaa8072d5fa0/68747470733a2f2f692e696d6775722e636f6d2f325035753235782e706e67)](https://camo.githubusercontent.com/4d4650eb726f4c0571931e080798c6112b956944fc97184610dadaa8072d5fa0/68747470733a2f2f692e696d6775722e636f6d2f325035753235782e706e67)

### Tutorials &amp; articles

[](#tutorials--articles)

I plan to expand this chapter with more tutorials and articles. If you write something about this package let me know, so that I can update this chapter.

**Screencasts:**

- [Adding comments to your Laravel application](https://www.youtube.com/watch?v=YhA0CSX1HIg) by Andre Madarang.

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

[](#installation)

From the command line:

```
composer require anil/comments
```

### Run migrations

[](#run-migrations)

We need to create the table for comments.

```
php artisan migrate
```

### Add Commenter trait to your User model

[](#add-commenter-trait-to-your-user-model)

Add the `Commenter` trait to your User model so that you can retrieve the comments for a user:

```
use Anil\Comments\Commenter;

class User extends Authenticatable
{
    use Notifiable, Commenter;
}
```

### Add Commentable trait to models

[](#add-commentable-trait-to-models)

Add the `Commentable` trait to the model for which you want to enable comments for:

```
use Anil\Comments\Commentable;

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

### Publish Config &amp; configure (optional)

[](#publish-config--configure-optional)

Publish the config file (optional):

```
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=config
```

### Publish views (customization)

[](#publish-views-customization)

The default UI is made for Bootstrap 4, but you can change it however you want.

```
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=views
```

### Publish Migrations (customization)

[](#publish-migrations-customization)

You can publish migration to allow you to have more control over your table

```
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=migrations
```

### Publish translations (customization)

[](#publish-translations-customization)

The package currently only supports English, but I am open to PRs for other languages.

```
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=translations
```

Usage
-----

[](#usage)

In the view where you want to display comments, place this code and modify it:

```
@comments(['model' => $book])

```

In the example above we are setting the `commentable_type` to the class of the book. We are also passing the `commentable_id` the `id` of the book so that we know to which book the comments relate to. Behind the scenes, the package detects the currently logged in user if any.

If you open the page containing the view where you have placed the above code, you should see a working comments form.

### View only approved comments

[](#view-only-approved-comments)

To view only approved comments, use this code:

```
@comments([
    'model' => $book,
    'approved' => true
])

```

### Paginate comments

[](#paginate-comments)

Pagination paginates by top level comments only, meaning that if you specify the number of comments per page to be 1, and that one comment has 100 replies, it will display that one comment and all of its replies.

It was not possible to do it any other way, because if I paginate by all comments (parent and child) you will end up with blank pages since the comments components loops parent comments first and then uses recursion for replies.

To use pagination, use this code:

```
@comments([
    'model' => $user,
    'perPage' => 2
])

```

Replace `2` with any number you want.

### Configure maximum indentation level

[](#configure-maximum-indentation-level)

By default the replies go up to level three. After that they are "mashed" at that level.

```
- 0
    - 1
        - 2
            - 3

```

You can configure the maximum indentation level like so:

```
@comments([
    'model' => $user,
    'maxIndentationLevel' => 1
])

```

Events
------

[](#events)

This package fires events to let you know when things happen.

- `Anil\Comments\Events\CommentCreated`
- `Anil\Comments\Events\CommentUpdated`
- `Anil\Comments\Events\CommentDeleted`

REST API
--------

[](#rest-api)

To change the controller or the routes, see the config.

```
Route::post('comments', '\Anil\Comments\CommentController@store')->name('comments.store');
Route::delete('comments/{comment}', '\Anil\Comments\CommentController@destroy')->name('comments.destroy');
Route::put('comments/{comment}', '\Anil\Comments\CommentController@update')->name('comments.update');
Route::post('comments/{comment}', '\Anil\Comments\CommentController@reply')->name('comments.reply');

```

### POST `/comments`

[](#post-comments)

Request data:

```
'commentable_type' => 'required|string',
'commentable_id' => 'required|string|min:1',
'message' => 'required|string'

```

### PUT `/comments/{comment}`

[](#put-commentscomment)

- {comment} - Comment ID.

Request data:

```
'message' => 'required|string'

```

### POST `/comments/{comment}`

[](#post-commentscomment)

- {comment} - Comment ID.

Request data:

```
'message' => 'required|string'

```

License
-------

[](#license)

Comments is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance66

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 90.6% 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

Every ~268 days

Total

5

Last Release

54d ago

Major Versions

v1.0.1 → 2.x-dev2026-03-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbf68af3401ccbe162a5a25a7850c53fba8e8fddc8271df21d367a79b68ad0e2?d=identicon)[anilkumarthakur60](/maintainers/anilkumarthakur60)

---

Top Contributors

[![anilkumarthakur60](https://avatars.githubusercontent.com/u/16583802?v=4)](https://github.com/anilkumarthakur60 "anilkumarthakur60 (29 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")

---

Tags

laraveleloquentcommentsreactionspolymorphiccommentingthreaded-comments

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/anil-comments/health.svg)

```
[![Health](https://phpackages.com/badges/anil-comments/health.svg)](https://phpackages.com/packages/anil-comments)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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