PHPackages                             alayubi/laravel-comment - 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. alayubi/laravel-comment

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

alayubi/laravel-comment
=======================

Add comment to your Laravel app.

v0.1.1(3y ago)0231PHPPHP ^7.3|^8.0

Since May 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/shalahuddinalayubi/laravel-comment)[ Packagist](https://packagist.org/packages/alayubi/laravel-comment)[ RSS](/packages/alayubi-laravel-comment/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (5)Used By (1)

Instalation
-----------

[](#instalation)

```
composer require alayubi/laravel-comment
```

you must publish the migration with:

```
php artisan vendor:publish --tag=lara-comment-migrations
```

and rerun the migration.

Config
------

[](#config)

You can publish the config file with:

```
php artisan vendor:publish --tag=lara-comment-config
```

Usage
-----

[](#usage)

### Commentable

[](#commentable)

If you want a model can be commented you can implements `\Lara\Comment\Contracts\IsCommentable` interface and add `\Lara\Comment\Commentable` trait for the implementation.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Lara\Comment\Commentable;
use Lara\Comment\Contracts\IsCommentable;

class Post extends Model implements IsCommentable
{
    use Commentable;
}
```

### Commentator

[](#commentator)

Commentator is a model that comment on a model. Implements `\Lara\Comment\Contracts\IsCommentator\` interface on a model if you want to your model to be a commentator and add `\Lara\Comment\Commentator` trait for the implementation.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Lara\Comment\Commentator;
use Lara\Comment\Contracts\IsCommentator;

class User extends Model implements IsCommentator
{
    use Commentator;
}
```

### Creating Comments

[](#creating-comments)

To create a comment to a model you should first create the view with form.

```

    Submit

```

at least you provide the textarea tag HTML with `comment` name. Then you may create a route to handle the request. In your controller you can use `\Lara\Comment\CommentService` class and `store` method to create a comment.

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

$user = Auth::user();

$comment = CommentService::for($post, $user)
            ->store();
```

### Updating comment

[](#updating-comment)

```
$commentToUpdate = Comment::find(1);

$user = Auth::user();

$comment = CommentService::for($commentToUpdate, $user)
            ->update();
```

### Destory comment

[](#destory-comment)

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

$user = Auth::user();

$comment = CommentService::for($post, $user)
            ->destroy();
```

Frontend
--------

[](#frontend)

Before you start with the default frontend you must integrate your app with:

1. vue
2. tailwindcss

The command below will publish the nested comment frontend. With nested comment you can reply a comment. You can publish the frotend with:

```
php artisan vendor:publish --tag=lara-comment-vue
```

it will create views in resources/views/vendor/comment and vue component in resources/js/components/comment directory. Don't forget to copy this code below to your app.js.

```
Vue.component('edit-comment', require('./components/comment/EditComment.vue').default);
Vue.component('reply-comment', require('./components/comment/ReplyComment.vue').default);
```

After published you are be able to customise the css to fit with your view. To use the frontend nested comment you may include it in your view and pass the commentable model to it.

```
@include('vendor.comment.comment-list', ['commentable' => $post])
```

The code will render the comments with nested indentation belongs to `$post`. Change the `indentation` in config file so that you can reply a comment in more deeper indentation. You can imagine the indentation like:

```
- 0
    - 1
        - 2

```

Routes
------

[](#routes)

By default there are three routes for common task.

1. create visit `route('comments.comments.store')` or `/comments/{comment}/comments` with POST method to create a comment on the comment.
2. update visit `route('comments.update')` or `/comments/{comment}` with PUT method to update the comment.
3. destroy visit `route('comments.destroy')` or `/comments/{comment}` with DELETE method to remove the comment from storage.

If you don't want to use the default route put `false` value in `route` inside setting file comment.php.

```
'route' => false
```

Validation Rule and Requested Data
----------------------------------

[](#validation-rule-and-requested-data)

`\Lara\Comment\Validation\DefaultValidator` is the default validator. Validator is a class that responsible to get and validate the data from user.

If you want to chnage default behavior of validation or what kind of data you will store to storage you can extends `\Lara\Comment\Validation\Validator` abstract class then you must implement public function data() and public function rules(). From the class you can access commentator model and request object.

### data()

[](#data)

The data function is resposible to return what kind of data to store.

```
public function data()
{
    return [
        'user_id' => $this->commentator->id,
        'comment' => $this->request->get('comment'),
    ];
}
```

### rules()

[](#rules)

The rules function is responsible to define what kind of validation rules to run.

```
public function rules()
{
    return [
        'user_id' => 'required',
        'comment' => 'required',
    ];
}
```

Don't forget to change the config validator value to your implementation.

```
return [
    'validator' => \Lara\Comment\Validation\DefaultValidator::class,
]
```

### validateWithBag() method

[](#validatewithbag-method)

If you have multiple form for comment then you want to display error message You can use `validateWithBag()` method to validate with bag.

```
$commentToUpdate = Comment::find(1);

$user = Auth::user();

$comment = CommentService::for($commentToUpdate, $user)
            ->validateWithBag()
            ->update();
```

so whene validation error occur you may the access the error bag

```
{{ $errors->{$comment->id . 'PUT'}->first('comment') }}
```

you can access the name error bag with combination of the `commentable` id and the method `PUT` and `POST`

Redirector
----------

[](#redirector)

Redirector will redirect to the URL if validation fails. The default redirector is \\Lara\\Comment\\Redirect\\RedirectBack. This will redirect back with URL fragment #validation-comment-error. If you wish to change this default behavior you could create your own redirect by extends \\Lara\\Comment\\Redirect\\Redirect abstract class and change the redirector value on configuration comment file to your own implementation.

```
return [
    'redirector' => \Lara\Comment\Redirect\RedirectBack::class
];
```

Policy
------

[](#policy)

You can create your own policy to authorize the action. To create policy class just run the laravel artisan command. For the complete guide see laravel documentation.

```
php artisan make:policy CommentPolicy
```

Don't forget to change `policy` class in config file.

```
return [
    'policy' => \Lara\Comment\CommentPolicy::class
]
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

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.

###  Release Activity

Cadence

Every ~20 days

Total

2

Last Release

1432d ago

### Community

Maintainers

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

---

Top Contributors

[![shalahuddinalayubi](https://avatars.githubusercontent.com/u/59285897?v=4)](https://github.com/shalahuddinalayubi "shalahuddinalayubi (5 commits)")

### Embed Badge

![Health badge](/badges/alayubi-laravel-comment/health.svg)

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

###  Alternatives

[stuttter/wp-user-profiles

A sophisticated way to edit users in WordPress

11219.3k1](/packages/stuttter-wp-user-profiles)[fof/analytics

Tracks analytics using Google Analytics, Google Optimize/GTM and Matomo

3543.1k](/packages/fof-analytics)[malarzm/collections

Various implementations of Doctrine's Collection interface

2368.1k](/packages/malarzm-collections)[chrico/wp-fields

Package which provides some re-usable fields for WordPress.

1981.2k](/packages/chrico-wp-fields)[aertmann/history

An improved history backend module for Neos

1070.2k](/packages/aertmann-history)

PHPackages © 2026

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