md0/regenerator is a Laravel package for laravel regenerator.
It currently has 3 GitHub stars and 43 downloads on Packagist.
Install it with composer require md0/regenerator.
Discover more Laravel packages by md0
or browse all Laravel packages to compare alternatives.
Last updated
A quick report generator for Laravel based on SQL queries.
This is a tool intended for site/app admins that need to quickly create decent looking reports for display or export using only SQL select statements and a few parameters. Uses Bootstrap 3/4 classes for formatting, but can also output to an array if you need to customize the final look.
This package does not include a GUI for managing the reports. Please check out ReGenerator for Backpack if you need to edit reports from the admin interface.
Should work on any version of Laravel above 5.6, but was only tested on v8.
Require the package via Composer:
composer require md0/reportgenerator
Run the database migrations:
php artisan migrate
Publish the assets (only needed for charts):
php artisan vendor:publish --provider="MD0\ReGenerator\ReGeneratorServiceProvider" --tag="assets"
Publish the configuration file (to modify the default settings for new reports):
php artisan vendor:publish --provider="MD0\ReGenerator\ReGeneratorServiceProvider" --tag="config"
Publish the views (to modify the chart options and/or PDF headers):
php artisan vendor:publish --provider="MD0\ReGenerator\ReGeneratorServiceProvider" --tag="views"
Publish the language files. There are only three translatable strings (for the aggregate functions) so you can either edit them inside resources/lang/vendor/regenerator folder or just add them to your main translation file.
provider="MD0\ReGenerator\ReGeneratorServiceProvider" --tag="lang"
To use ReGenerator you can either:
use MD0\ReGenerator\Report;
class MyClass {
function report() {
$report = new Report;
$myReport = $report->setReport('my_report')->getHtml();
}
}
use MD0\ReGenerator\Facades\Report;
class MyClass {
function report() {
Report::setReport('my_report')->getHtml();
}
}
To get started, all you need is access to the table/tables from which you need to extract the raports and your actual select statement:
Report::set('query', 'select name, email from users')->getHtml();
This will generate an ad-hoc (on the fly) report. To create a permanent report using a default set of options use the create method:
Report::create('my_report', 'select name, email from users')->getHtml();
This will add a new report to the database and generate it in HTML form. You may then include it as a variable anywhere on your view.
To access a previously created report you need to use the setReport method and (optionally) set any custom preferences before generating it:
Report::setReport('my_report')
->set('pdfPageSize', 'letter')
->set('pdfPageOrientation', 'landscape')
->getPdf();
To make any customization permanent use the update method:
Report::setReport('my_report')->update('PdfPageSize', 'letter');
Check the next section for a complete list of methods and properties that you can use with ReGenerator.
Each report can have one or more associated properties that can be set at runtime or commited to the database:
$validParameters = [
'condition1' => 'where active=1',
'condition2' => 'and verified=1',
];
setReport(string $name): object | bool
Sets the active report.
set(string $property, string $value): object
Sets a property for the current report. Can be used with stored reports (after setReport()) or chained with itself to generate ad-hoc reports.
getValue(int $line, int $column): string | bool
Returns a specific value from a report, useful when you have fixed size (x/y) reports.
getArray(): string
Returns the current report as associative array. Must be called after setReport() or set().
getHtml(): string
Returns the current report as HTML formatted using Bootstrap classes. Must be called after setReport() or set().
getPdf(): string
Returns the current report as a PDF file within a variable. Must be called after setReport() or set(). To display or download the PDF file set the Content-Type and Content-Disposition header directives:
return response()->make($pdfReport, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="test.pdf"',
]);
getChart(): string
Returns the current report as canvas Chart, ready to be inserted into any view. Must be called after setReport() or set().
getReports([string $property], [string $value]): array | bool
Returns an array containing all the reports matching a set criteria. If no property is provided the method returns a list of all available reports.
create(string $name, string $query, [string $database], [array $parameters]): object | bool
Creates a new report entry in the database.
update(string | array $data, [string $value]): object | bool
Updates a report. Must be called after the setReport() method.
delete(): bool
Deletes a report. Must be called after the setReport() method.
To change the default parameters for new reports publish the config file as described above and adjust the defaults array to your liking.
To overwrite the default PDF page layout (to add a logo, etc.), publish the views and edit views/vendor/md0/regenerator/pdf/report.blade.php to suit your needs. If you need multiple templates create your own views and point to them with the pdfTemplate property.
Use if you need to tweak Chart.js's settings publish the views and edit views/vendor/md0/regenerator/chart/report.blade.php. If you need multiple templates create your own views and point to them with the chartTemplate property.
Please send your improvement suggestions or report bugs / errors in the Issues section.
Distributed under the GPL-3.0 License. See LICENSE for more information.
ReGenerator uses the following open source libraries to generate raports. Please consult their respective pages for more information on usage and available customizations: