jobzmall/reportable

适用于 Laravel 8 的可报告的多态 Eloquent 模型

10.0.0 2022-05-03 22:45 UTC

README

Build Status PHP from Packagist Latest Version License

安装

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

$ composer require artisanry/reportable

要开始使用,您需要发布供应商资产并迁移

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

用法

设置模型

<?php

namespace App;

use Artisanry\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();

获取未评判的报告(没有结论的报告)

Report::unjudged(); // returns query builder.

更改用户报告模型

Set your user model in the config('auth.providers.users.model');

测试

$ phpunit

安全

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

鸣谢

该项目存在归功于所有 贡献者

许可证

Mozilla 公共许可证版本 2.0 (MPL-2.0)。