PHP code example of x-laravel / commentable

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

    

x-laravel / commentable example snippets


use XLaravel\Commentable\Concerns\Commentable;
use XLaravel\Commentable\Concerns\Commenter;
use XLaravel\Commentable\Contracts\CanComment;
use XLaravel\Commentable\Contracts\HasComments;

class User extends Authenticatable implements CanComment
{
    use Commenter;
}

class Post extends Model implements HasComments
{
    use Commentable;
}

$post->addComment('Great post!');                  // anonymous
$post->addComment('Great post!', $user);
$user->comment($post, 'Great post!');

$post->addReply($comment, 'I agree!', $user);
$user->reply($post, $comment, 'I agree!');

$post->rootComments()->withCount('replies')->with('commenter')->paginate(20);
$comment->replies()->withCount('replies')->with('commenter')->paginate(10);

$post->comments;         // every comment on the post, replies 

$comment->delete();       // soft delete
$comment->restore();
$comment->forceDelete();  // deletes the replies with it through the foreign key
bash
php artisan vendor:publish --tag=commentable-config
bash
php artisan model:prune --model="XLaravel\Commentable\Models\Comment"