Comments is a package for managing comments on features like Posts
PHP >=7.3
$ composer require rockbuzz/lara-comments
php artisan vendor:publish --provider="Rockbuzz\LaraComments\ServiceProvider"
php artisan migrate
Add the Commenter and Commentable
trait in models for:
use Rockbuzz\LaraComments\Traits\{Commentable, Commenter};
class User extends Authenticatable
{
use Commenter;
}
class Post extends Model
{
use Commentable;
}
$user->comments(): HasMany;
$user->commentOn(Model $commentable, string $body, string $title = null): Comment;
$user->likes(): BelongsToMany;
$user->likeTo(Comment $comment): void;
$user->dislikeTo(Comment $comment): void;
$post->comments(): MorphMany;
$post->hasComments(): bool;
$post->asPending($comment): void;
$post->approve($comment): void;
$post->unapprove($comment): void;
$comment->commenter(): BelongsTo;
$comment->commentable(): MorphTo;
$comment->children(): HasMany;
$comment->parent(): BelongsTo
$comment->isPending(): bool;
$comment->isApprove(): bool;
$comment->isUnapprove(): bool;
Scope
Comment::approved();
Comment::pending();
Comment::unapproved();
\Rockbuzz\LaraComments\Events\AsPendingEvent::class;
\Rockbuzz\LaraComments\Events\ApprovedEvent::class;
\Rockbuzz\LaraComments\Events\UnapprovedEvent::class;
The Lara Comments is open-sourced software licensed under the MIT license.