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

ActiveLibrary

waad/laravel-comments
=====================

Add comments to your Laravel application

v1.1.0(2y ago)019MITPHPPHP ^8.0

Since Mar 25Pushed 2y agoCompare

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

READMEChangelog (2)DependenciesVersions (4)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->addComment('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 waad/laravel-comments
```

The package will automatically register itself.

You can publish the migration with:

```
php artisan vendor:publish --provider="Waad\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="Waad\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 Waad\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 Waad\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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~30 days

Total

3

Last Release

1080d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44348636?v=4)[Waad Mawlood](/maintainers/waadmawlood)[@waadmawlood](https://github.com/waadmawlood)

---

Top Contributors

[![waadmawlood](https://avatars.githubusercontent.com/u/44348636?v=4)](https://github.com/waadmawlood "waadmawlood (11 commits)")[![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)")[![Edgarborras94](https://avatars.githubusercontent.com/u/6952403?v=4)](https://github.com/Edgarborras94 "Edgarborras94 (1 commits)")[![sschlein](https://avatars.githubusercontent.com/u/2911113?v=4)](https://github.com/sschlein "sschlein (1 commits)")[![tkaratug](https://avatars.githubusercontent.com/u/4394344?v=4)](https://github.com/tkaratug "tkaratug (1 commits)")[![nickbyte](https://avatars.githubusercontent.com/u/5063465?v=4)](https://github.com/nickbyte "nickbyte (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![lukasmu](https://avatars.githubusercontent.com/u/28652053?v=4)](https://github.com/lukasmu "lukasmu (1 commits)")

---

Tags

beyondcodecommentslaravel-comments

### Embed Badge

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

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

###  Alternatives

[beyondcode/laravel-comments

Add comments to your Laravel application

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

Symfony Var-Dump Server for Laravel

1.6k42.6M163](/packages/beyondcode-laravel-dump-server)[beyondcode/laravel-query-detector

Laravel N+1 Query Detector

2.0k6.7M12](/packages/beyondcode-laravel-query-detector)[beyondcode/laravel-er-diagram-generator

Generate ER diagrams from your Laravel models.

2.0k1.4M2](/packages/beyondcode-laravel-er-diagram-generator)[beyondcode/laravel-self-diagnosis

Perform various self diagnosis tests on your Laravel application.

1.5k1.2M4](/packages/beyondcode-laravel-self-diagnosis)[beyondcode/laravel-mailbox

Handle incoming emails in your Laravel application.

1.1k1.0M4](/packages/beyondcode-laravel-mailbox)

PHPackages © 2026

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