balaremember/laravel-comments-service

适用于laravel项目的树形评论系统

dev-master 2018-08-30 08:33 UTC

This package is not auto-updated.

Last update: 2024-09-21 14:12:17 UTC


README

适用于laravel项目的树形评论系统。

安装

  1. 将以下git仓库定义添加到您的composer.json文件中

    "repositories": [
        ...
        {
            "type": "vcs",
            "url": "https://github.com/balaremember/laravel-comments-service"
        }
        ...
    ]
    
  2. 运行composer install

    composer require balaremember/laravel-comments-service
    
  3. 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"
  4. 现在您已经有了带有参数的评论配置文件

    'userModel' => Path to your user model, (default: App\User)
    'perPage' => Number of comments on one page, (default: 10)
    'levelDepth' => Depth of nesting. (default: 3)

    配置 变量的完整描述

  5. 在您的 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 文档