PHP code example of ashiq-kodali / eazyreport

1. Go to this page and download the library: Download ashiq-kodali/eazyreport 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/ */

    

ashiq-kodali / eazyreport example snippets


use EazyReport\EazyReport;

// Load template and bind data
$builder = EazyReport::load('path/to/invoice.rtpl')
    ->data([
        'invoice' => [
            'number' => 'INV-2026-001',
            'date' => '2026-10-03',
            'dueDate' => '2026-10-17',
        ],
        'customer' => [
            'name' => 'Acme Corporation',
            'address' => '100 Innovation Way',
            'city' => 'San Francisco, CA',
        ],
        'items' => [
            ['description' => 'Enterprise Cloud Hosting', 'qty' => 12, 'rate' => 250.0, 'amount' => 3000.0],
            ['description' => 'Dedicated Migration Support', 'qty' => 40, 'rate' => 85.0, 'amount' => 3400.0],
        ],
        'totals' => [
            'subtotal' => 6400.0,
            'tax' => 512.0,
            'total' => 6912.0,
        ],
    ])
    ->param('currency', 'USD');

// 1. Generate standalone HTML for browser viewing or printing
$html = $builder->toHtml();

// 2. Generate PDF binary bytes
$pdfBytes = $builder->toPdf();

// 3. Save to disk
$builder->savePdf('storage/reports/invoice.pdf');

// 4. Stream or download directly in HTTP response
$builder->downloadPdf('invoice-INV-2026-001.pdf');

namespace App\Http\Controllers;

use EazyReport\Laravel\Facades\EazyReport;
use App\Models\Order;
use Illuminate\Http\Response;

class InvoiceController extends Controller
{
    public function download(Order $order)
    {
        $templatePath = resource_path('reports/invoice.rtpl');

        $pdf = EazyReport::load($templatePath)
            ->data([
                'order' => $order->toArray(),
                'customer' => $order->customer->toArray(),
                'items' => $order->items->toArray(),
            ])
            ->param('printedBy', auth()->user()->name ?? 'System')
            ->toPdf();

        return response($pdf, 200, [
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'attachment; filename="order-' . $order->id . '.pdf"',
        ]);
    }
}