ryangjchandler / laravel-comments
一个为 Laravel 服务的简单评论包。
v1.0.0
2024-03-12 21:22 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0
- illuminate/database: ^11.0
- spatie/laravel-package-tools: ^1.16.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2024-08-29 09:10:57 UTC
README
此包为您的 Laravel 应用程序提供了一种极其简单的评论系统。
如果您正在寻找带有 UI 组件的包,我强烈推荐使用 Spatie 的 laravel-comments 包,该包自带 Livewire 支持。
安装
您可以通过 Composer 安装此包
composer require ryangjchandler/laravel-comments
该包会自动注册迁移,因此无需发布任何内容,只需运行它们。
php artisan migrate
您可以使用以下命令发布配置文件:
php artisan vendor:publish --tag="comments-config"
这是已发布配置文件的内容
return [ 'model' => \RyanChandler\Comments\Models\Comment::class, 'user' => \App\Models\User::class, ];
用法
首先在您的模型上使用 RyanChandler\Comments\Concerns\HasComments
特性。
use RyanChandler\Comments\Concerns\HasComments; class Post extends Model { use HasComments; }
此特性为您的模型添加了一个 comments(): MorphMany
关联。它还添加了一个新的 comment()
方法,可用于快速将评论添加到模型。
$post = Post::first(); $post->comment('Hello, world!');
默认情况下,该包将使用已认证用户的 ID 作为“评论者”。您可以通过向 comment()
方法提供自定义的 User
来自定义此功能。
$post->comment('Hello, world!', user: User::first());
该包还支持评论的 parent -> children
关系。这意味着一个评论可以 belongTo
另一个评论。
$post->comment('Thanks for commenting!', parent: Comment::find(2));
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 变更日志。
贡献
有关详细信息,请参阅 贡献指南。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
致谢
许可协议
MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件。