PHP code example of langleyfoxall / eloquent-report-generator

1. Go to this page and download the library: Download langleyfoxall/eloquent-report-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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'));