PHPackages                             fabrizio/commentator - 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. fabrizio/commentator

ActiveLibrary

fabrizio/commentator
====================

A Laravel package that lets you add a comment section to your pages.

02PHP

Since Nov 14Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Commentator 🤭 (Supports Laravel 8)
==================================

[](#commentator--supports-laravel-8)

If you ever need comments for your projects, here is something to get you started.

Demo
----

[](#demo)

Play around with this [demo project](https://commentator-demo.herokuapp.com/)

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

[](#installation)

```
$ composer require fabrizio/commentator
```

Run the following command to publish config and migration files.

```
php artisan vendor:publish --provider="Plmrlnsnts\Commentator\CommentatorServiceProvider"
```

Run the migrations.

```
php artisan migrate
```

Next, register the routes to manage comments in the `boot` method of your `AppServiceProvider`.

```
use Plmrlnsnts\Commentator\Commentator;

public function boot()
{
    Commentator::routes();
}
```

Usage
-----

[](#usage)

Add the `HasComments` trait to your eloquent models.

```
use Plmrlnsnts\Commentator\HasComments;

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

### Comments

[](#comments)

To add a comment to your model, use the `addComment` method.

```
$article = Article::first();

$article->addComment(['body' => 'Better call Saul!']);
```

If you also support media files, pass an additional `media` attribute.

```
$article->addComment([
    'body' => 'Yo Mr. White! Check this out.',
    'media' => 'https://unsplash.com/photos/yplNhhXxBtM',
]);
```

### Mentions

[](#mentions)

A user can be mentioned using `@` symbol, followed by a combination of alphanumeric characters, underscores and hypens.

```
$comment = $article->addComment(['body' => '@Pinkman']);
```

Call the `mentionedNames` method to retrieve an array of mentions.

```
$comment->mentionedNames();

// ['Pinkman']
```

Mentions are transformed to anchor tags by calling `asHtml` to a comment instance.

```
$comment->asHtml();

// @Pinkman
```

> The `asHtml` strips any html element except anchor tags to prevent xss attacks.

### Replies

[](#replies)

If you want to support nested comments, use the `addReply` method.

```
$comment->addReply(['body' => 'I am Heisenberg.']);
```

JSON API
--------

[](#json-api)

Commentator provides a JSON API that you may use to manage comments. This saves you the trouble of having to manually code controllers for creating, updating, and deleting comments.

##### `GET /comments`

[](#get-comments)

This route returns a paginated list of comments for a given model. You need to pass the `commentableKey`, and an optional `sort` parameter to order the result from `latest`.

```
const params = {
    commentableKey: 'SOMESTRING',
    sort: 'latest',
    page: 1,
    perPage: 10,
}

axios.get('/comments', { params })
    .then(response => {
        console.log(response.data)
    })
```

##### `POST /comments`

[](#post-comments)

This route is used to create new comments. It accepts two pieces of data: a body and/or a media.

```
const data = {
    body: 'Yo, Mr. White! Check this out.',
    media: 'https://unsplash.com/photos/yplNhhXxBtM',
    commentableKey: 'SOMESTRING',
}

axios.post('/comments', data)
    .then(response => {
        console.log(response.data)
    })
```

##### `PATCH /comments/{comment}`

[](#patch-commentscomment)

This route is used to update comments. It accepts two pieces of data: a body and/or a media.

```
const data = {
    body: 'Changed',
}

axios.patch(`/comments/${commment.id}`, data)
    .then(response => {
        console.log(response.data)
    })
```

> Only comments that are *owned* by the authenticated user can be updated.

##### `DELETE /comments/{comment}`

[](#delete-commentscomment)

This route is used to delete comments.

```
axios.delete(`/comments/${commment.id}`)
    .then(response => {
        //
    })
```

> Only comments that are *owned* by the authenticated user can be deleted.

##### `GET /comments/{comment}/replies`

[](#get-commentscommentreplies)

This route returns a paginated list of replies for a comment. You may pass an optional `sort` parameter to order the result from `latest`.

```
const params = {
    sort: 'latest',
    page: 1,
    perPage: 10,
}

axios.get(`/comments/${comment.id}/replies`, { params })
    .then(response => {
        console.log(response.data)
    })
```

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

[](#post-commentscommentreplies)

This route is used to reply to a comment. It accepts two pieces of data: a body and/or a media.

```
const data = {
    body: 'Yo, Mr. White! Check this out.',
    media: 'https://unsplash.com/photos/yplNhhXxBtM',
}

axios.post(`/comments/${comment.id}/replies`, data)
    .then(response => {
        console.log(response.data)
    })
```

> Replies are **comments too!** So you can re-use the same routes for updating and deleting replies.

Configuration
-------------

[](#configuration)

### User Model

[](#user-model)

Commentator references the current `User` model as the author when adding comments. If you are using a different namespace, change them in `config/commentator.php`.

```
return [
    'models' => [
        'user' => \App\Models\User::class
    ]
];
```

### Mentions

[](#mentions-1)

The regular expression used to identify mentions, and the parsed link can be modified from the `config` file.

```
return [
   'mentions' => [
        'regex' => '/@([\w\-]+)/',
        'replace' => '@$1'
    ]
];
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b1fab03d3d3b5166fce903233e80874c9c2875569cd58cf5c4af6df132d3d85?d=identicon)[Fabrizio](/maintainers/Fabrizio)

---

Top Contributors

[![F4brizio](https://avatars.githubusercontent.com/u/68043260?v=4)](https://github.com/F4brizio "F4brizio (3 commits)")

### Embed Badge

![Health badge](/badges/fabrizio-commentator/health.svg)

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

PHPackages © 2026

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