PHP code example of sohrab-az / laravel-comment

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

    

sohrab-az / laravel-comment example snippets


return [
    'default_status' => \SohrabAzinfar\Comment\Enums\CommentStatusEnum::Pending->value,

    // Maximum depth of nested replies
    'depth' => 5,
];

use SohrabAzinfar\Comment\Traits\HasComments;

class Post extends Model
{
    use HasComments;
}

$post->addComment(
    body: 'This is a comment',
    author: auth()->user()
);

$post->addComment(
    body: 'Hello world',
    author: null,
    guest: [
        'name' => 'John',
        'email' => '[email protected]'
    ]
);

$post->replyTo($comment, 'This is a reply', auth()->user());

$comments = $post->queryComment()
    ->approved()
    ->roots()
    ->withReplies()
    ->get();

$comments = $post->queryComment()->paginate(10);

use SohrabAzinfar\Comment\Enums\CommentStatusEnum;

CommentStatusEnum::Pending;
CommentStatusEnum::Approved;
CommentStatusEnum::Rejected;

$post->approve($comment);
$post->reject($comment);

$post->deleteComment($comment);

$post = Post::find(1);

$comment = $post->addComment('Nice post!', auth()->user());

$post->replyTo($comment, 'Thanks!');
bash
php artisan vendor:publish --tag=comment-config
php artisan migrate