b61/laravel-reportable

Laravel 5 的可报告多态 Eloquent 模型

0.2.1 2018-12-02 10:03 UTC

This package is auto-updated.

Last update: 2024-08-29 05:12:32 UTC


README

我们为门户评论提供的评论报告系统。

安装

使用 Composer 在项目的根目录中安装此包。

$ composer require b61/laravel-reportable

要开始,您需要发布供应商资源和迁移

php artisan vendor:publish --provider="BrianFaust\Reportable\ReportableServiceProvider" && php artisan migrate

用法

设置模型

<?php

namespace App;

use ActivismBE\Reportable\HasReports;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasReports;
}

示例

用户模型报告帖子模型

$post->report([
    'reason' => str_random(10),
    'meta' => ['some more optional data, can be notes or something'],
], $user);

为报告创建结论并添加用户模型作为“评判者”(有助于稍后查看谁或什么得出了这个结论)

$report->conclude([
    'conclusion' => 'Your report was valid. Thanks! We\'ve taken action and removed the entry.',
    'action_taken' => 'Record has been deleted.' // This is optional but can be useful to see what happend to the record
    'meta' => ['some more optional data, can be notes or something'],
], $user);

获取报告模型的结论

$report->conclusion;

获取报告模型的评判者(只有存在结论时才可用)

$report->judge(); // Just a shortcut for $report->conclusion->judge

获取一个数组,包含所有曾经“评判”过某事的评判者

Report::allJudges();

测试

$ phpunit

安全

如果您在此包中发现安全漏洞,请发送电子邮件至 hello@brianfaust.me。所有安全漏洞都将得到及时解决。

鸣谢

许可

MIT © Brian Faust