<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
langleyfoxall / eloquent-report-generator example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use LangleyFoxall\EloquentReportGenerator\Traits\Reportable;
class User extends Model
{
use Reportable;
// ...
// Report format
$format = (new CsvReportFormat());
//$format = (new PdfReportFormat());
//$format = (new MarkdownReportFormat());
//$format = (new HtmlReportFormat());
// Report generation
User::generateReport()
->format($format)
->query(function ($query) {
// Restrict the records used in the report
$query->where('created_at', '>=' '2018-01-01');
})
->fields(['email', 'name', 'created_at'])
->fieldMap([
// Change how fields appear in the report
'email' => 'Email address',
'name' => 'Name',
'created_at' => 'Joined Date',
])
->dataRowManipulator(function (DataRow $dataRow) {
// Format the 'name' field
$name = $dataRow->getDataItemByFieldName('name');
$name->value = ucwords($name);
}
->save(storage_path('app/report.csv'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.