rockbuzz / lara-comments
Comments 是一个用于管理如帖子等功能的评论的包
9.0.0
2024-07-27 15:49 UTC
Requires
- php: >=8.1
- bensampo/laravel-enum: ^6.0
Requires (Dev)
- orchestra/testbench: ^7.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-09-01 11:28:43 UTC
README
Comments 是一个用于管理如帖子等功能的评论的包
要求
PHP >=7.3
安装
$ composer require rockbuzz/lara-comments
php artisan vendor:publish --provider="Rockbuzz\LaraComments\ServiceProvider"
php artisan migrate
在模型中添加 Commenter and Commentable
特性
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;
范围
Comment::approved(); Comment::pending(); Comment::unapproved();
事件
\Rockbuzz\LaraComments\Events\AsPendingEvent::class; \Rockbuzz\LaraComments\Events\ApprovedEvent::class; \Rockbuzz\LaraComments\Events\UnapprovedEvent::class;
许可
Lara Comments 是开源软件,受 MIT 许可证 许可。