jaktech / anaphora
Anaphora是一个强大的Laravel报告包,简化了有洞察力的报告的生成和检索。使用Anaphora,您可以轻松创建、管理和检索Laravel应用程序的报告,提供跟踪、分析和可视化重要数据的流畅体验。
v0.1.1
2023-11-23 13:02 UTC
Requires
- php: ^7.2|~8.0.0|~8.1.0|~8.2.0
- illuminate/support: *
Requires (Dev)
- orchestra/testbench: ^8.15
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-09-24 07:22:12 UTC
README
简介
这个Laravel Eloquent扩展提供了根据日期使用模型进行记录的功能。
此包提供了一个事件,当保存或创建任何Eloquent模型时将生成唯一的slug。
安装
composer require jaktech/anaphora
用法
入门指南
考虑以下表架构进行分层数据
Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); });
在您的模型中使用Reportable特质来处理报告
class User extends Model { use \Jakteck\Anaphora\Traits\Reportable; }
作用域
此特质提供了查询作用域,可以按日期过滤数据
yearlyReport($year = null):提供按年记录。默认情况下将提供当前年的记录。thisYearReport():提供当前年的记录。lastYearReport():提供上一年的记录。monthlyReport($month = null, $year = null):提供按月记录。默认情况下将提供当前月的记录。thisMonthReport():提供当前月的记录。lastMonthReport():提供上个月的记录。thisWeekReport():提供本周的记录。(周一至周日)lastWeekReport():提供上周的记录。(周一至周日)dailyReport($date = null):提供按日记录。默认情况下将提供今天的记录。todayReport():提供今天的记录。yesterdayReport():提供昨天的记录。hourlyReport($from = null, $to = null, $date = null):提供按小时记录。默认情况下将提供从上一个小时到当前小时的记录。
年度报告
/*Only Current Year Users*/ $users = User::yearlyReport()->get(); // or /*2018 Users*/ $year = 2018; // or Carbon date $users = User::yearlyReport($year)->get();
本年报告
/*Only Current Year Users*/ $users = User::thisYearReport()->get();
去年报告
/*Only Last Year Users*/ $users = User::lastYearReport()->get();
月度报告
/*Only Current Month Users*/ $users = User::monthlyReport()->get(); // or /*November Current Year Users*/ $month = 11; // or Carbon date $users = User::monthlyReport($month)->get(); // or /*November 2018 Year Users*/ $month = 11; // or Carbon date $year = 2018; // or Carbon date $users = User::monthlyReport($month, $year)->get();
本月报告
/*Only Current Month Users*/ $users = User::thisMonthReport()->get();
上月报告
/*Only Last Month Users*/ $users = User::thisMonthReport()->get();
本周报告
/*Only Current Week Users (Mon - Sun)*/ $users = User::thisWeekReport()->get();
上周报告
/*Only Last Week Users (Mon - Sun)*/ $users = User::lastWeekReport()->get();
每日报告
/*Only Today's Users*/ $users = User::dailyReport()->get(); // or /*December 27, 2019 Users*/ $date = '2019-12-27'; // or Carbon date $users = User::dailyReport($date)->get();
今日报告
/*Only Today's Users*/ $users = User::todayReport()->get();
昨日报告
/*Only Yesterday's Users*/ $users = User::yesterdayReport()->get();
每小时报告
/*Only Last hour to current hour's Users*/ $users = User::hourlyReport()->get(); // or /*Only 7 am to 2pm Users*/ $from = '07:00'; // or Carbon time $to = '14:00'; // or Carbon time $users = User::hourlyReport($from, $to)->get(); // or /*Only 7 am to 2pm at December 27, 2019 Users*/ $from = '07:00'; // or Carbon time $to = '14:00'; // or Carbon time $date = '2019-12-27'; // or Carbon date $users = User::hourlyReport($from, $to, $date)->get();
自定义查询
您可以实现自己的条件或对查询执行任何操作。
$users = User::dailyReport()->where('status', '=', 'inactive')->get();
高级用法
$data = []; $date = Carbon::now()->firstOfMonth(); while ($date <= Carbon::now()->endOfMonth()) { $users = User::dailyReport($date) ->when('condition', function ($query) { $query->where('column', 'value'); }) ->whereNotIn('column', ['value1', 'value2']) ->where('column', 'operator', 'value') ->get(); $data[] = $users; $date = $date->copy()->addDay(); }
许可协议
这是一个开源的Laravel库,受MIT许可协议许可。