agoalofalife/reports

Laravel 中创建和下载报告的 UI

v0.3.0 2019-04-11 07:26 UTC

This package is auto-updated.

Last update: 2024-09-29 04:36:55 UTC


README

需求:PHP 版本 >= 7.1.0 Laravel 版本 >= 5.5

not support Laravel version 5.8 & >

这是什么?

此包提供报告的预置 UI 和一些代码。

报告将包含扩展: pdf, xlxs, xls, csv

在 Laravel 体系中,我们创建报告并编写代码。就这么简单!

安装

composer require agoalofalife/reports
php artisan reports:install

语言环境

在文件 config/app.php 中选择您的语言。

该包提供两种语言

  • ru
  • en

Blade 和 UI

在您的模板中,您需要粘贴以下代码

  <body>
    @include('reports::app')
    ...

计划任务

您必须添加计划任务,以分离进程。

// App\Console\Kernel
use agoalofalife\Reports\Console\ParseReportsCommand;

  $schedule->command(ParseReportsCommand::class)->everyMinute();

开发流程

您创建新的报告文件

php artisan make:report NameReport

config/reports.php 配置文件中插入

  'reports' => [
          \App\Reports\TestReport::class
    ],

填写类

<?php
declare(strict_types=1);
namespace App\Reports;

use agoalofalife\Reports\Contracts\HandlerReport;
use agoalofalife\Reports\Report;

class TestReport extends Report implements HandlerReport
{
    /**
     * Disk for filesystem
     * @var string
     */
    public $disk = 'public';

  /**
     * Format export : xls, xlsx, pdf, csv
     * @var string
     */
    public $extension = 'xlsx';

     /**
     * Get file name
     * @return string
     */
    public function getFilename() : string
    {
        return 'TestReport';
    }

    /**
     * Get title report
     * @return string
     */
    public function getTitle() : string
    {
        return 'Test';
    }

    /**
     * Get description report
     * @return string
     */
    public function getDescription() : string
    {
        return 'Description test report';
    }

    /**
     * @param $excel
     * @return bool
     */
    public function handler($excel) : bool
    {
      $excel->sheet('Sheetname', function ($sheet) {
            $sheet->rows(array(
                array('test1', 'test2'),
                array('test3', 'test4')
            ));
        });
      return true;
    }
}

属性 $disk,文件系统的磁盘名称。

属性 $extension,文件的扩展类型。

方法 getFilename 适当地返回文件名。

方法 getTitle 返回 UI 中的标题。

方法 getDescription 返回 UI 中的描述。

方法 handler 是基本方法。包使用 外部 包。

方法是一个小包装器。

通知

一旦报告准备就绪,您可以发送 通知

为此,您需要实现接口 agoalofalife\Reports\Contracts\NotificationReport

方法 getNotifiable 返回 notifiable,它有一个方法 routeNotificationFor

方法 getNotification 返回 Notification 类型。

    // implements agoalofalife\Reports\Contracts\NotificationReport
    public function getNotifiable()
    {
        return User::where('email', 'test@gmail.com')->get()->first();
    }

    public function getNotification(): Notification
    {
        return new InvoicePaid();
    }
// app/User.php

    public function routeNotificationForSlack($notification)
    {
        return 'hook';
    }