dev-pirate / lara-report-craft
一个Laravel包,可以轻松创建和管理报告
v1.0.4
2024-01-20 03:22 UTC
Requires
- php: >=8.1
- ext-json: *
Requires (Dev)
- mockery/mockery: ^1.2
- orchestra/testbench: ^3.7
README
LaraReportCraft 是一个用于管理和创建报告的 Laravel 库,可以轻松实现美观的单页表格视图和打印功能。此外,该包还提供了自定义报告的标题、页眉、页脚、列和数据行的能力。
通过 composer 安装
运行以下命令以获取最新版本
composer require dev-pirate/lara-report-craft
发布配置
运行以下命令以发布包配置文件
php artisan vendor:publish --provider="DevPirate\LaraReportCraft\Providers\LaraReportCraftProvider"
现在你应该有一个 config/lara-report-craft.php 文件,允许你配置此包的基本设置。
添加路由
将以下代码添加到你的路由文件中
Route::middleware([ 'api', \Fruitcake\Cors\HandleCors::class, ])->group(function() { LaraReportCraft::routes(); }); // \Fruitcake\Cors\HandleCors middleware are required here to manage cors
创建自定义报告类
在继续之前,请确保已按照 Laravel 的安装说明安装了包。
创建你的类
首先,你需要在你的报告类中扩展 DevPirate\LaraReportCraft\Facades\GeneralReport 类,这需要自定义数据和函数逻辑。
以下示例应为你提供一个大致的思路。显然,你应该根据需要做出任何必要的修改。
<?php namespace App\Reports; use App\Models\Example; use Carbon\Carbon; use DevPirate\LaraReportCraft\Facades\GeneralReport; class ExampleReport extends GeneralReport { protected string $reportTitle = 'Example report testing'; protected array $columns = [ ['field' => 'order_date', 'title' => 'Order Date'], ['field' => 'region', 'title' => 'Région'], ['field' => 'rep', 'title' => 'Rep order'], ['field' => 'item', 'title' => 'Item N°'], ['field' => 'unit', 'title' => 'Unit code'], ]; public function generate_report(): array { return array_map(function ($example) { return [ 'order_date' => Carbon::parse($example['orderDate'])->format('d/m/Y') ?? '', 'region' => $example['region'], 'rep' => $example['rep'], 'item' => $example['item'], 'unit' => $example['unit'] ]; }, Example::all()->toArray()); } }
配置文件
让我们回顾一下我们之前发布的 config/lara-report-craft.php 文件中的部分选项。
首先,是
<?php return [ 'reports_path' => app_path('Reports') // other configuration parameters ];
.