nutnet/laravel-comments

用于 actuallymab/laravel-comment 包的扩展。允许以访客身份评论并添加其他元信息。

0.1.4 2017-09-26 13:20 UTC

This package is auto-updated.

Last update: 2024-09-17 09:28:20 UTC


README

原始的 laravel-comment 包是创建 Laravel 评论系统的良好起点,但该包默认不支持附加关于用户或评论的元信息,或以访客身份评论。本扩展修复了这些问题。

安装和配置

要安装包,运行

composer require nutnet/laravel-comments

接下来,通过将服务提供者添加到您的应用配置中启用包

// config/app.php
'providers' => [
    ...
    Nutnet\LaravelComments\ServiceProvider::class,
    ...
];

可选地添加 Nutnet\LaravelComments\Facades\Commenter 门面的别名。

用法

所有用法与原始包相同,除了某些时刻

  1. 使用 Nutnet\LaravelComments\CanComment 特性替代原始特性。
  2. 使用 Nutnet\LaravelComments\Commentable 特性替代原始特性。
  3. 使用 Nutnet\LaravelComments\Models\Comment 模型替代原始模型。
作为授权用户
use Nutnet\LaravelComments\Services\Commenter;
use Nutnet\LaravelComments\Facades\Commenter as CommenterFacade;

// ... some other code

public function comment(Commenter $commenter)
{
    // variant 1
    $commenter->comment($product, 'Test comment', $user, ['meta' => 'test']);
    
    // variant 2, without meta
    $user->comment($product, 'Test comment', $rate);
    
    // variant 3
    CommenterFacade::comment($product, 'Test comment', $user, ['meta' => 'test']);
}
作为访客
use Nutnet\LaravelComments\Services\Commenter;
use Nutnet\LaravelComments\Facades\Commenter as CommenterFacade;

// ... some other code

public function comment(Commenter $commenter)
{
    // variant 1
    $commenter->commentAsGuest($product, 'Test comment', ['meta' => 'test']);
    
    // variant 2, without meta
    CommenterFacade::commentAsGuest($product, 'Test comment', ['meta' => 'test']);
}