PHP code example of yarmat / laravel-comment

1. Go to this page and download the library: Download yarmat/laravel-comment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yarmat / laravel-comment example snippets


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

'limit' => '5',

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

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

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

        'destroy' => ['auth'],

        'get' => [],

        'update' => [],

        'count' => []
    ],

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

'comment_relations' => ['user'],

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

        'auth' => [ // For Auth Users
            'message' => ['     'name' => 'string', new \Yarmat\Comment\Rules\Spam(), new \Yarmat\Comment\Rules\AllowableSite()]
        ],
        'messages' => []

    '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' => '',

'spam_list' => ['spam'],

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

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

 

use Illuminate\Database\Eloquent\Model;
use Yarmat\Comment\Contracts\CommentContract;
use Yarmat\Comment\Traits\HasCommentTrait;

class Post extends Model implements CommentContract
{
    use HasCommentTrait;
}    

 

use Illuminate\Foundation\Auth\User as Authenticatable;
use Yarmat\Comment\Traits\CommenterTrait;

class User extends Authenticatable
{
    use CommenterTrait;
}    
html
 {!! \Comment::config('Post', $post->id) !!}