PHPackages                             petersuhm/commentable - 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. petersuhm/commentable

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

petersuhm/commentable
=====================

Comments model for Laravel 4

201756[4 issues](https://github.com/petersuhm/commentable/issues)[1 PRs](https://github.com/petersuhm/commentable/pulls)PHP

Since Apr 16Pushed 13y ago4 watchersCompare

[ Source](https://github.com/petersuhm/commentable)[ Packagist](https://packagist.org/packages/petersuhm/commentable)[ RSS](/packages/petersuhm-commentable/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Commentable
===========

[](#commentable)

Commentable is a comments model for Laravel 4.

- [Installation](#installation)
- [Basic usage](#basic-usage)
    - [Inheritance](#inheritance)
    - [Interfaces](#interfaces)
    - [Adding comments](#adding-comments)
    - [Retrieving comments](#retrieving-comments)
- [Advanced usage](#advanced-usage)
- [Support and suggestions](#support-and-suggestions)

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

[](#installation)

Require `"petersuhm/commentable": "dev-master"` in your `composer.json` file and run `composer update`:

```
"require-dev": {
    "petersuhm/commentable": "dev-master"
}

```

Add the `CommentableServiceProvider` to the `providers` array in `app/config/app.php`:

```
'providers' => array(

    ...

    'Petersuhm\Commentable\CommentableServiceProvider',

);
```

Add a `Comment` alias to the `aliases` array in `app/config/app.php`:

```
'aliases' => array(

    ...

    'Comment' => 'Petersuhm\Commentable\Comment',

);
```

Finally, you need to run the migration for the `petersuhm_commentable_comments`table:

```
php artisan migrate --package=petersuhm/commentable

```

Basic usage
-----------

[](#basic-usage)

In order to use Commentable's `Comment` model, you have the following options:

1. Inherit from the `Commentable` and `Authorable` models, provided by Commentable. This way, you also get acces to the helper methods provided by these models.
2. Implement the `CommentableInterface` and `AuthorableInterface` interfaces in your models. This is useful, if you don't inherit from Eloquent in your models (maybe you use Ardent or something).
3. A mixture of both.

### Inheritance

[](#inheritance)

If you choose to let your models inherit from the `Commentable` and `Authorable`models, provided by Commentable, you gain access the helper methods, that these classes offer. This is the easiest way to utilise Comment in your app. You simply declare your models this way:

```
use Petersuhm\Commentable\Authorable;
use Petersuhm\Commentable\Commentable;

class User extends Authorable {}

class BlogPost extends Commentable {}
```

### Interfaces

[](#interfaces)

If you don't wish to inherit from the `Commentable` and `Authorable` models, you can instead implement the `CommentableInterface` and `AuthorableInterface`interfaces. This way, you will not be able to use the helper methods from `Commentable` and `Authorable`, unless you add them to your own models. In order to use Commentable's interfaces, declare your models this way:

```
use Petersuhm\Commentable\AuthorableInterface;
use Petersuhm\Commentable\CommentableCommentable;

class User extends Eloquent implements AuthorableInterface {

    public function comments()
    {
        return $this->morphMany('Comment', 'authorable');
    }
}

class BlogPost extends Eloquent implements CommentableInterface {

    public function comments()
    {
        return $this->morphMany('Comment', 'commentable');
    }
}
```

### Adding comments

[](#adding-comments)

The `Comment` class has an `add()` function, which returns an unsaved comment instance. You can add a new comment like this:

```
$body = 'This is a test comment';
$authorable = User::first();
$commentable = BlogPost::first();

Comment::add($body, $authorable, $commentable)->save();
```

If you use inheritance, you can also use the `addComment` method:

```
$body = 'This is a test comment';
$authorable = User::first();
$commentable = BlogPost::first();

$commentable->addComment($body, $authorable)->save();

// Or the other way around:

$authorable->addComment($body, $commentable)->save();
```

### Retrieving comments

[](#retrieving-comments)

Thanks to Eloquent, you can retrieve comments just like you would expect:

```
$authorable = User::first();
$commentable = BlogPost::first();

$authorable->comments;
$commentable->comments;
```

Advanced usage
--------------

[](#advanced-usage)

If you wish to overwrite the `Comment` class provided by Commentable, you can do so by implementing the `CommentInterface`interface in your own `Comment` model.

Support and suggestions
-----------------------

[](#support-and-suggestions)

If you have any problems, or if you have some suggestions, discover a bug etc., feel free to open an issue!

Changelog
---------

[](#changelog)

- **Added indexes to comments table**: Run `composer update` followed by `php artisan migrate --package=petersuhm/commentable`.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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://avatars.githubusercontent.com/u/1430546?v=4)[Peter Suhm](/maintainers/petersuhm)[@petersuhm](https://github.com/petersuhm)

---

Top Contributors

[![petersuhm](https://avatars.githubusercontent.com/u/1430546?v=4)](https://github.com/petersuhm "petersuhm (31 commits)")

### Embed Badge

![Health badge](/badges/petersuhm-commentable/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198628.3k10](/packages/pgvector-pgvector)

PHPackages © 2026

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