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

Abandoned → [yarmat/laravel-comment](/?search=yarmat%2Flaravel-comment)Library[Utility &amp; Helpers](/categories/utility)

yarmat/laravel-comment
======================

Package for using comments with Vue in Laravel 5

1.1(7y ago)036MITPHPPHP &gt;=7.0

Since Jan 23Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (4)Used By (0)

Laravel comments with Vue.js
============================

[](#laravel-comments-with-vuejs)

Package for using comments with Vue.js component

Installing
----------

[](#installing)

```
composer require yarmat/laravel-comment
```

You must publish Vue Component, Languages, migration and config;

```
php artisan vendor:publish --provider="Yarmat\Comment\CommentServiceProvider"
```

After publishing you can create comments-tables by running the migrations:

```
php artisan migrate
```

Add middleware

```
    protected $routeMiddleware = [
        ...
        'comment' => 'Yarmat\Comment\Http\Middleware\CommentMiddleware'
    ];
```

Settings
--------

[](#settings)

You should edit config file

```
config/comment.php
```

##### Limit

[](#limit)

Limit of comments when will you send a request for the route get (route('comment.get'))

```
'limit' => '5',
```

##### Order

[](#order)

```
'default_order' => 'DESC', // OR ASC. DESC - Newest, ASC - Oldest
```

##### Models

[](#models)

Change the User Model

```
'models' => [
     'user' => 'Your User Model Path'
 ]
```

##### Prefix

[](#prefix)

Change prefix, if you need to change route prefix

```
{prefix}.store
{prefix}.destroy
{prefix}.update
{prefix}.count
{prefix}.get
```

##### Middleware

[](#middleware)

You can assign a middleware to each route:

```
    'middleware' => [

       'store' => ['throttle:15'],

        'destroy' => ['auth'],

        'get' => [],

        'update' => [],

        'count' => []
    ],
```

##### Models that will implement comments

[](#models-that-will-implement-comments)

```
    'models_with_comments' => [
        'Blog' => App\Models\Blog::class,
    ],
```

##### Relations

[](#relations)

Add relations for you comments

```
'comment_relations' => ['user'],
```

or

```
'comment_relations' => ['user' => function($query) {
    $query->select(['id', 'name', 'email']);
}, 'likes' => function($query){
    $query-> ...
}],
```

##### Validation

[](#validation)

```
        'auth' => [ // For Auth Users
            'message' => ['required', 'string', new \Yarmat\Comment\Rules\Spam(), new \Yarmat\Comment\Rules\AllowableSite()]
        ],
        'not_auth' => [ // For Not Auth Users
            'name' => 'required|alpha',
            'email' => 'required|email',
            'message' => ['required', 'string', new \Yarmat\Comment\Rules\Spam(), new \Yarmat\Comment\Rules\AllowableSite()]
        ],
        'messages' => []
```

##### TransformComment

[](#transformcomment)

Function that transform Comments Model before you get it in the Vue component

```
    'transformFunction' => function ($item) {
        return [
            'id' => $item->id,
            'message' => $item->message,
            'isVisibleForm' => false,
            'date' => \Date::parse($item->created_at)->diffForHumans(),
            'user' => [
                'name' => $item->user->name ?? $item->name,
                'email' => $item->user->email ?? $item->email
            ],
            'children' => []
        ];
    },
```

##### Allowable Tags

[](#allowable-tags)

Php function strip\_tags() that cuts out all tags except those that you list in the string

```
'allowable_tags' => '',
```

##### Spam Words

[](#spam-words)

You can list spam words. Comments with these words will not be published.

```
'spam_list' => ['spam'],
```

##### Spam Sites

[](#spam-sites)

You can list allowable sites. The comment will not be published if there is an unresolved link in it.

```
'allowable_sites' => ['site.com'],
```

Usage
-----

[](#usage)

F.e. you have model Post and you want to attach comments to it

##### Step 1

[](#step-1)

Add model to config

```
    'models_with_comments' => [
         'Post' => App\Post::class,
    ],
```

##### Step 2

[](#step-2)

Add **Yarmat\\Comment\\Traits\\HasCommentTrait** and **Yarmat\\Comment\\Contracts\\CommentContract** to your model Post:

```
