PHP code example of anil / comments

1. Go to this page and download the library: Download anil/comments 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/ */

    

anil / comments example snippets


use Anil\Comments\Commenter;

class User extends Authenticatable
{
    use Notifiable, Commenter;
}

use Anil\Comments\Commentable;

class Post extends Model
{
    use Commentable;
}

'reactions' => [
    'enabled' => true,
    'types'   => ['like', 'dislike'],
],

'guest_commenting' => false,

$post->comments();                                // all comments
$post->approvedComments();                        // only approved
$post->latestComments(5);                         // 5 most recent
$post->commentsWithReplies();                     // top-level + eager-loaded replies
$post->totalComments();                           // count
$post->commentsByUser($userId, $commenterType);   // filter by user
$post->commentsInDateRange($start, $end);         // date range
$post->commentsWithAttributes(['approved' => true]);
$post->commentsWithRelations(['commenter']);

Post::mostCommented(5);                           // static — top 5 most commented

'controller' => \App\Http\Controllers\MyCommentController::class,
bash
composer migrate
bash
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=config
bash
# Views
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=views

# Migrations
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=migrations

# Translations
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=translations

# All at once
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=comments
bash
php artisan vendor:publish --provider="Anil\Comments\ServiceProvider" --tag=translations