PHPackages                             caocanhlinh/laravel-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. caocanhlinh/laravel-comments

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

caocanhlinh/laravel-comments
============================

Comments for Laravel.

01PHP

Since Sep 13Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Comments
========

[](#comments)

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

[![Become a Patron](https://camo.githubusercontent.com/16fde1abb7601eba23de38f592bc54e3a7d10da24ac58db594d7fab32d449d46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d65253230612d506174726f6e2d6639363835342e7376673f7374796c653d666f722d7468652d6261646765)](https://www.patreon.com/laravelista)

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 laravelista/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 Laravelista\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 Laravelista\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="Laravelista\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="Laravelista\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="Laravelista\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="Laravelista\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.

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

REST API
--------

[](#rest-api)

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

```
Route::post('comments', '\Laravelista\Comments\CommentController@store')->name('comments.store');
Route::delete('comments/{comment}', '\Laravelista\Comments\CommentController@destroy')->name('comments.destroy');
Route::put('comments/{comment}', '\Laravelista\Comments\CommentController@update')->name('comments.update');
Route::post('comments/{comment}', '\Laravelista\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'

```

Upgrading from older versions (troubleshoot)
--------------------------------------------

[](#upgrading-from-older-versions-troubleshoot)

Before creating an issue, read [this](./UPGRADE.md).

Sponsors &amp; Backers
----------------------

[](#sponsors--backers)

I would like to extend my thanks to the following sponsors &amp; backers for funding my open-source journey. If you are interested in becoming a sponsor or backer, please visit the [Backers page](https://mariobasic.com/backers).

Contributing
------------

[](#contributing)

Thank you for considering contributing to Comments! The contribution guide can be found [Here](https://mariobasic.com/contributing).

Code of Conduct
---------------

[](#code-of-conduct)

In order to ensure that the open-source community is welcoming to all, please review and abide by the [Code of Conduct](https://mariobasic.com/code-of-conduct).

License
-------

[](#license)

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

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

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

---

Top Contributors

[![mabasic](https://avatars.githubusercontent.com/u/1839930?v=4)](https://github.com/mabasic "mabasic (23 commits)")[![caocanhlinh](https://avatars.githubusercontent.com/u/44583838?v=4)](https://github.com/caocanhlinh "caocanhlinh (7 commits)")[![rocramer](https://avatars.githubusercontent.com/u/4487988?v=4)](https://github.com/rocramer "rocramer (6 commits)")[![GrassiSupport](https://avatars.githubusercontent.com/u/15674321?v=4)](https://github.com/GrassiSupport "GrassiSupport (2 commits)")[![imnotjames](https://avatars.githubusercontent.com/u/1551593?v=4)](https://github.com/imnotjames "imnotjames (2 commits)")[![bosunski](https://avatars.githubusercontent.com/u/15146515?v=4)](https://github.com/bosunski "bosunski (2 commits)")[![maartenderie](https://avatars.githubusercontent.com/u/19903985?v=4)](https://github.com/maartenderie "maartenderie (1 commits)")[![mattrabe](https://avatars.githubusercontent.com/u/1786783?v=4)](https://github.com/mattrabe "mattrabe (1 commits)")[![papoms](https://avatars.githubusercontent.com/u/1764001?v=4)](https://github.com/papoms "papoms (1 commits)")[![Riaan-ZA](https://avatars.githubusercontent.com/u/1535640?v=4)](https://github.com/Riaan-ZA "Riaan-ZA (1 commits)")[![shanecp](https://avatars.githubusercontent.com/u/1654017?v=4)](https://github.com/shanecp "shanecp (1 commits)")[![thewebartisan7](https://avatars.githubusercontent.com/u/57477934?v=4)](https://github.com/thewebartisan7 "thewebartisan7 (1 commits)")[![AbdallaMohammed](https://avatars.githubusercontent.com/u/41541325?v=4)](https://github.com/AbdallaMohammed "AbdallaMohammed (1 commits)")[![whakru](https://avatars.githubusercontent.com/u/22603145?v=4)](https://github.com/whakru "whakru (1 commits)")[![fabianfetting](https://avatars.githubusercontent.com/u/9155615?v=4)](https://github.com/fabianfetting "fabianfetting (1 commits)")[![fey](https://avatars.githubusercontent.com/u/697178?v=4)](https://github.com/fey "fey (1 commits)")[![Jipem](https://avatars.githubusercontent.com/u/2027318?v=4)](https://github.com/Jipem "Jipem (1 commits)")[![joelwmale](https://avatars.githubusercontent.com/u/3906839?v=4)](https://github.com/joelwmale "joelwmale (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")

### Embed Badge

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

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

###  Alternatives

[jyxon/gdpr-cookie-compliance

A library to comply with the GDPR law.

5848.5k](/packages/jyxon-gdpr-cookie-compliance)[umpirsky/composer-permissions-handler

Composer script handling directories permissions by making them writable both by the web server and the command line user.

6630.3k](/packages/umpirsky-composer-permissions-handler)[verbb/social-poster

Automatically post entries to social media.

918.5k](/packages/verbb-social-poster)[dktapps/pmforms

Form API library for PocketMine-MP plugins

522.3k1](/packages/dktapps-pmforms)[hexadog/laravel-menus-manager

Dynamic Menus Management package for your Laravel application

184.5k](/packages/hexadog-laravel-menus-manager)[melios/page-builder

Improvements for the built-in Magento PageBuilder module

131.4k](/packages/melios-page-builder)

PHPackages © 2026

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