balaremember / laravel-comments-service
适用于laravel项目的树形评论系统
dev-master
2018-08-30 08:33 UTC
Requires
- php: >=7.1.0
- illuminate/config: ~5.0
- illuminate/container: ~5.0
- illuminate/contracts: ~5.0
- illuminate/database: ~5.0
- illuminate/http: ~5.0
- illuminate/support: ~5.0
Requires (Dev)
- mockery/mockery: 0.9.*
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-21 14:12:17 UTC
README
适用于laravel项目的树形评论系统。
安装
-
将以下git仓库定义添加到您的composer.json文件中
"repositories": [ ... { "type": "vcs", "url": "https://github.com/balaremember/laravel-comments-service" } ... ] -
运行composer install
composer require balaremember/laravel-comments-service -
Laravel
>= laravel5.5
ServiceProvider将会自动附加
其他
在您的
config/app.php文件中,将Balaremember\LaravelCommentsService\CommentsServiceProvider::class添加到providers数组的末尾'providers' => [ ... Balaremember\LaravelCommentsService\CommentsServiceProvider::class, ],
如果使用Lumen
$app->register(Balaremember\LaravelCommentsService\CommentsServiceProvider::class);
发布配置
php artisan vendor:publish --provider "Balaremember\LaravelCommentsService\CommentsServiceProvider" -
现在您已经有了带有参数的评论配置文件
'userModel' => Path to your user model, (default: App\User) 'perPage' => Number of comments on one page, (default: 10) 'levelDepth' => Depth of nesting. (default: 3)
配置 变量的完整描述
-
在您的 AppServiceProvider 中自定义多态类型,例如
- 要将评论连接到您的模型,您需要
class YourModel extends Model { public function comments() { return $this->morphMany(Balaremember\LaravelCommentsService\Entities\Comment::class, 'commentable'); } }
- 默认情况下,Laravel会使用完全限定的类名来存储相关模型的类型。但是,您可能希望将数据库与应用程序的内部结构解耦。
use Illuminate\Database\Eloquent\Relations\Relation; Relation::morphMap([ 'posts' => 'App\Post', 'videos' => 'App\Video', ]);
更多信息请参阅 Laravel 文档