rezaghz/laravel-reports 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rezaghz/laravel-reports

Composer 安装命令:

composer require rezaghz/laravel-reports

包简介

Laravel reports package for implementing reports (eg: Spam,Violence,Child Abuse,illegal Drugs etc) on Eloquent models.

README 文档

README

laravel-reports

Laravel reports package for implementing reports (eg: Spam,Violence,Child Abuse,illegal Drugs, etc.) on Eloquent models.

Requirements

  • PHP 8.2 or higher
  • Laravel 6.x, 7.x, 8.x, 9.x, 10.x, 11.x, or 12.x

Installation

Download package into the project using Composer.

$ composer require rezaghz/laravel-reports

Registering package

Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

For Laravel 5.4 or earlier releases version include the service provider within app/config/app.php:

'providers' => [
    Rezaghz\Laravel\Reports\ReportsServiceProvider::class,
],

Database Migration

If you want to make changes in migrations, publish them to your application first.

$ php artisan vendor:publish --provider="Rezaghz\Laravel\Reports\ReportsServiceProvider" --tag=laravel-reports-migrations

Run database migrations.

$ php artisan migrate

Usage

Prepare Reports (User) Model

Use Rezaghz\Laravel\Reports\Contracts\ReportsInterface contract in model which will perform report behavior on reportable model and implement it and use Rezaghz\Laravel\Reports\Traits\Reports trait.

use Rezaghz\Laravel\Reports\Traits\Reports;
use Rezaghz\Laravel\Reports\Contracts\ReportsInterface;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements ReportsInterface
{
    use Reports;
}

Prepare Reportable Model

Use Rezaghz\Laravel\Reports\Contracts\ReportableInterface contract in model which will get report behavior and implement it and use Rezaghz\Laravel\Reports\Traits\Reportable trait.

use Illuminate\Database\Eloquent\Model;
use Rezaghz\Laravel\Reports\Traits\Reportable;
use Rezaghz\Laravel\Reports\Contracts\ReportableInterface;

class Article extends Model implements ReportableInterface
{
    use Reportable;
}

Available Methods

Report

$user->reportTo($article, 'spam');

$article->report('spam'); // current login user
$article->report('spam', $user);

Remove Report

Removing report of user from reportable model.

$user->removeReportFrom($article);

$article->removeReport(); // current login user
$article->removeReport($user);

Toggle Report

The toggle report method will add a report to the model if the user has not reported. If a user has already reported, then it will replace the previous report with a new report. For example, if the user has reported 'spam' on the model. Now on toggles report to 'violence' then it will remove the 'spam' and stores the 'violence' report.

If a user has reported spam then on toggle report with spam. It will remove the report.

$user->toggleReportOn($article, 'spam');

$article->toggleReport('spam'); // current login user
$article->toggleReport('spam', $user);

Boolean check if user reported on model

$user->isReportedOn($article));

$article->is_reported; // current login user
$article->isReportBy(); // current login user
$article->isReportBy($user);

Report summary on model

$article->reportSummary();
$article->report_summary;

// example
$article->report_summary->toArray();
// output
/*
[
    "spam" => 5,
    "violence" => 2,
    "illegal_drugs" => 4,
    "child_abuse" => 1
]
*/

Get collection of users who reported on model

$article->reportsBy();

Scopes

Find all articles reported by user.

Article::whereReportedBy()->get(); // current login user

Article::whereReportedBy($user)->get();
Article::whereReportedBy($user->id)->get();

Report on Model

// It will return the Report object that is reported by given user.
$article->reported($user);
$article->reported(); // current login user
$article->reported; // current login user

$user->reportedOn($article);

Events

On each report added \Rezaghz\Laravel\Reports\Events\OnReport event is fired.

On each report removed \Rezaghz\Laravel\Reports\Events\OnDeleteReport event is fired.

Testing

Run the tests with:

$ composer test

Or run PHPUnit directly:

$ vendor/bin/phpunit

Changelog

v2.0.0 (2025-01-08)

  • BREAKING: Updated to support Laravel 12.x
  • BREAKING: Requires PHP 8.2 or higher
  • Updated migration to use modern Laravel 12 patterns
  • Fixed method naming inconsistencies
  • Improved type hints and return types
  • Updated testing framework compatibility

v1.0.0 (2023-09-28)

  • Initial release
  • Support for Laravel 6.x - 10.x
  • Basic reporting functionality

rezaghz/laravel-reports 适用场景与选型建议

rezaghz/laravel-reports 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 204 次下载、GitHub Stars 达 23, 最近一次更新时间为 2022 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「report」 「laravel」 「Rating」 「like」 「eloquent」 「Rate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rezaghz/laravel-reports 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rezaghz/laravel-reports 我们能提供哪些服务?
定制开发 / 二次开发

基于 rezaghz/laravel-reports 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 204
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-07