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->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