agilepixels/laravel-commentable

为 Eloquent 模型添加评论的包

v1.3.0 2021-02-25 08:59 UTC

This package is auto-updated.

Last update: 2024-09-25 17:44:57 UTC


README

安装

您可以通过 composer 安装此包

composer require agilepixels/laravel-commentable

您必须使用以下命令发布迁移

php artisan vendor:publish --provider="AgilePixels\Commentable\CommentableServiceProvider" --tag="migrations"

迁移 comments

php artisan migrate

可选地,您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="AgilePixels\Commentable\CommentableServiceProvider" --tag="config"

使用特性

要为模型启用评论,请在模型上使用 AgilePixels\Commentable\Traits\HasComments 特性。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use AgilePixels\Commentable\Traits\HasComments;

class Product extends Model
{
    use HasComments;
}

您可以在作者模型上使用 AgilePixels\Commentable\Traits\AddsComments

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use AgilePixels\Commentable\Traits\AddsComments;

class User extends Model
{
    use AddsComments;
}