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

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

mdhesari/laravel-comments
=========================

Add comments to your Laravel application

2.0.0(2y ago)090MITPHPPHP ^7.2.5|^8.0|^8.1|^8.2

Since Jul 17Pushed 2y agoCompare

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

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

Add comments to your Laravel application
========================================

[](#add-comments-to-your-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9ae9911a9d95a9bf39d3754c8d252c7434ddbf470d8c660901d4a790b8d50d7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265796f6e64636f64652f6c61726176656c2d636f6d6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-comments)[![Build Status](https://camo.githubusercontent.com/6ec4ee1a7b618f7625f89dadf6ea52c1c6bf09209667be6825d59d5cbd2608de/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6265796f6e64636f64652f6c61726176656c2d636f6d6d656e74732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/beyondcode/laravel-comments)[![Quality Score](https://camo.githubusercontent.com/1ed91d6858a18d2ba7e236ac7f41adeb429b56dcd9c0a36fe5922bdea0869355/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6265796f6e64636f64652f6c61726176656c2d636f6d6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/beyondcode/laravel-comments)[![Total Downloads](https://camo.githubusercontent.com/7fdb2cf0fedf05936a673c2fbd7dc05df068a45b3296cf5240202cf77f5276b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6265796f6e64636f64652f6c61726176656c2d636f6d6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-comments)

Add the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested.

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

$post->comment('This is a comment');

$post->commentAsUser($user, 'This is a comment from someone else');
```

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

[](#installation)

You can install the package via composer:

```
composer require beyondcode/laravel-comments
```

The package will automatically register itself.

You can publish the migration with:

```
php artisan vendor:publish --provider="BeyondCode\Comments\CommentsServiceProvider" --tag="migrations"
```

After the migration has been published you can create the media-table by running the migrations:

```
php artisan migrate
```

You can publish the config-file with:

```
php artisan vendor:publish --provider="BeyondCode\Comments\CommentsServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

### Registering Models

[](#registering-models)

To let your models be able to receive comments, add the `HasComments` trait to the model classes.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;

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

### Creating Comments

[](#creating-comments)

To create a comment on your commentable models, you can use the `comment` method. It receives the string of the comment that you want to store.

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

$comment = $post->comment('This is a comment from a user.');
```

The comment method returns the newly created comment class.

Sometimes you also might want to create comments on behalf of other users. You can do this using the `commentAsUser` method and pass in your user model that should get associated with this comment:

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

$comment = $post->commentAsUser($yourUser, 'This is a comment from someone else.');
```

### Approving Comments

[](#approving-comments)

By default, all comments that you create are not approved - this is just a boolean flag called `is_approved` that you can use in your views/controllers to filter out comments that you might not yet want to display.

To approve a single comment, you may use the `approve` method on the Comment model like this:

```
$post = Post::find(1);
$comment = $post->comments->first();

$comment->approve();
```

### Auto Approve Comments

[](#auto-approve-comments)

If you want to automatically approve a comment for a specific user (and optionally model) you can let your User model implement the following interface and method:

```
namespace App\Models;

use BeyondCode\Comments\Contracts\Commentator;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements Commentator
{
    /**
     * Check if a comment for a specific model needs to be approved.
     * @param mixed $model
     * @return bool
     */
    public function needsCommentApproval($model): bool
    {
        return false;
    }

}
```

The `needsCommentApproval` method received the model instance that you want to add a comment to and you can either return `true` to mark the comment as **not** approved, or return `false` to mark the comment as **approved**.

### Retrieving Comments

[](#retrieving-comments)

The models that use the `HasComments` trait have access to it's comments using the `comments` relation:

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

// Retrieve all comments
$comments = $post->comments;

// Retrieve only approved comments
$approved = $post->comments()->approved()->get();
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Marcel Pociot](https://github.com/mpociot)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.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

Unknown

Total

1

Last Release

1027d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7504d2dd62302fe03079daa3b37a7cb007d7d67d9aacdf8f5128282d4ab15fcc?d=identicon)[mdhesari](/maintainers/mdhesari)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (10 commits)")[![sammagee](https://avatars.githubusercontent.com/u/3335946?v=4)](https://github.com/sammagee "sammagee (2 commits)")[![lukasmu](https://avatars.githubusercontent.com/u/28652053?v=4)](https://github.com/lukasmu "lukasmu (1 commits)")[![Mdhesari](https://avatars.githubusercontent.com/u/28428724?v=4)](https://github.com/Mdhesari "Mdhesari (1 commits)")[![nickbyte](https://avatars.githubusercontent.com/u/5063465?v=4)](https://github.com/nickbyte "nickbyte (1 commits)")[![sschlein](https://avatars.githubusercontent.com/u/2911113?v=4)](https://github.com/sschlein "sschlein (1 commits)")[![Edgarborras94](https://avatars.githubusercontent.com/u/6952403?v=4)](https://github.com/Edgarborras94 "Edgarborras94 (1 commits)")[![tkaratug](https://avatars.githubusercontent.com/u/4394344?v=4)](https://github.com/tkaratug "tkaratug (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")

---

Tags

beyondcodecommentslaravel-comments

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[beyondcode/laravel-comments

Add comments to your Laravel application

605414.2k2](/packages/beyondcode-laravel-comments)[beyondcode/laravel-vouchers

Allow users to redeem vouchers that are bound to models..

70763.4k2](/packages/beyondcode-laravel-vouchers)[beyondcode/laravel-favicon

Create dynamic favicons based on your environment settings.

37345.5k](/packages/beyondcode-laravel-favicon)[verbb/comments

Add comments to your site.

13753.1k](/packages/verbb-comments)[usamamuneerchaudhary/commentify

Easy Laravel Livewire Comments with TailwindCSS UI

23214.3k](/packages/usamamuneerchaudhary-commentify)[silverstripe/comments

Provides commenting functionality for your SilverStripe site.

41256.1k13](/packages/silverstripe-comments)

PHPackages © 2026

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