PHPackages                             coolsam/laravel-report-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. coolsam/laravel-report-generator

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

coolsam/laravel-report-generator
================================

Rapidly Generate Simple Pdf &amp; Excel Report on Laravel 5 (Using Barryvdh/DomPdf or Barryvdh/laravel-snappy &amp; maatwebsite/excel)

2.0.2(7y ago)08MITHTMLPHP &gt;=7.2

Since May 10Pushed 7y ago1 watchersCompare

[ Source](https://github.com/coolsam726/laravel-report-generator)[ Packagist](https://packagist.org/packages/coolsam/laravel-report-generator)[ RSS](/packages/coolsam-laravel-report-generator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (34)Used By (0)

Laravel Report Generators (PDF, CSV &amp; Excel)
================================================

[](#laravel-report-generators-pdf-csv--excel)

Rapidly Generate Simple Pdf Report on Laravel (Using [barryvdh/laravel-dompdf](https://github.com/barryvdh/laravel-dompdf) or [barryvdh/laravel-snappy](https://github.com/barryvdh/laravel-snappy)) or CSV / Excel Report (using [Maatwebsite/Laravel-Excel](https://github.com/Maatwebsite/Laravel-Excel))

This package provides a simple pdf, csv &amp; excel report generators to speed up your workflow

Installation
------------

[](#installation)

Add package to your composer:

```
composer require coolsam/laravel-report-generator

```

If you are running Laravel &gt; 5.5 that's all you need to do. If you are using Laravel &lt; 5.5 add the ServiceProvider to the providers array in config/app.php

```
Coolsam\ReportGenerator\ServiceProvider::class,

```

**Optionally**, you can add this to your aliases array in config/app.php

```
'PdfReport' => Coolsam\ReportGenerator\Facades\PdfReportFacade::class,
'ExcelReport' => Coolsam\ReportGenerator\Facades\ExcelReportFacade::class,
'CSVReport' => Coolsam\ReportGenerator\Facades\CSVReportFacade::class,

```

For more better speed on generating pdf report, I recommend you to use laravel snappy package. To using laravel snappy, you should install `wkhtmltopdf` to work with this package [(Jump to wkhtmltopdf installation)](#wkhtmltopdf-installation)

Information
-----------

[](#information)

This package can use either `cursor` or `chunk` method (Eloquent / Query Builder) so it can handle big data faster than chunk and minimizing memory usage.

MethodOn Versionchunk()1.0.\*cursor()^1.1.0Find the comparison between `chunk` and `cursor` in [here](https://qiita.com/ryo511/items/ebcd1c1b2ad5addc5c9d)

Also, You can use `PdfReport`, `ExcelReport` or `CSVReport` facade for shorter code that already registered as an alias.

### Example Display PDF Code

[](#example-display-pdf-code)

```
use PdfReport;

public function displayReport(Request $request)
{
    $fromDate = $request->input('from_date');
    $toDate = $request->input('to_date');
    $sortBy = $request->input('sort_by');

    $title = 'Registered User Report'; // Report title

    $meta = [ // For displaying filters description on header
        'Registered on' => $fromDate . ' To ' . $toDate,
        'Sort By' => $sortBy
    ];

    $queryBuilder = User::select(['name', 'balance', 'registered_at']) // Do some querying..
                        ->whereBetween('registered_at', [$fromDate, $toDate])
                        ->orderBy($sortBy);

    $columns = [ // Set Column to be displayed
        'Name' => 'name',
        'Registered At', // if no column_name specified, this will automatically seach for snake_case of column name (will be registered_at) column from query result
        'Total Balance' => 'balance',
        'Status' => function($result) { // You can do if statement or any action do you want inside this closure
            return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
        }
    ];

    // Generate Report with flexibility to manipulate column class even manipulate column value (using Carbon, etc).
    return PdfReport::of($title, $meta, $queryBuilder, $columns)
                    ->editColumn('Registered At', [ // Change column class or manipulate its data for displaying to report
                        'displayAs' => function($result) {
                            return $result->registered_at->format('d M Y');
                        },
                        'class' => 'left'
                    ])
                    ->editColumns(['Total Balance', 'Status'], [ // Mass edit column
                        'class' => 'right bold'
                    ])
                    ->showTotal([ // Used to sum all value on specified column on the last table (except using groupBy method). 'point' is a type for displaying total with a thousand separator
                        'Total Balance' => 'point' // if you want to show dollar sign ($) then use 'Total Balance' => '$'
                    ])
                    ->limit(20) // Limit record to be showed
                    ->stream(); // other available method: download('filename') to download pdf / make() that will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download()
}
```

Note: For downloading to excel / CSV, just change `PdfReport` facade to `ExcelReport` / `CSVReport` facade with no more modifications

### Data Manipulation

[](#data-manipulation)

```
$columns = [
    'Name' => 'name',
    'Registered At' => 'registered_at',
    'Total Balance' => 'balance',
    'Status' => function($customer) { // You can do data manipulation, if statement or any action do you want inside this closure
        return ($customer->balance > 100000) ? 'Rich Man' : 'Normal Guy';
    }
];
```

Will produce a same result with:

```
$columns = [
    'Name' => function($customer) {
        return $customer->name;
    },
    'Registered At' => function($customer) {
        return $customer->registered_at;
    },
    'Total Balance' => function($customer) {
        return $customer->balance;
    },
    'Status' => function($customer) { // You can do if statement or any action do you want inside this closure
        return ($customer->balance > 100000) ? 'Rich Man' : 'Normal Guy';
    }
];
```

### Report Output

[](#report-output)

[![Report Output with Grand Total](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-total.png)](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-total.png)

With this manipulation, you could do some **eager loading relation** like:

```
$post = Post::with('comments')->where('active', 1);

$columns = [
    'Post Title' => function($post) {
        return $post->title;
    },
    'Slug' => 'slug',
    'Latest Comment' => function($post) {
        return $post->comments->first()->body;
    }
];
```

### Example Code With Group By

[](#example-code-with-group-by)

Or, you can total all records by group using `groupBy` method

```
    ...
    // Do some querying..
    $queryBuilder = User::select(['name', 'balance', 'registered_at'])
                        ->whereBetween('registered_at', [$fromDate, $toDate])
                        ->orderBy('registered_at', 'ASC'); // You should sort groupBy column to use groupBy() Method

    $columns = [ // Set Column to be displayed
        'Registered At' => 'registered_at',
        'Name' => 'name',
        'Total Balance' => 'balance',
        'Status' => function($result) { // You can do if statement or any action do you want inside this closure
            return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
        }
    ];

    return PdfReport::of($title, $meta, $queryBuilder, $columns)
                    ->editColumn('Registered At', [
                        'displayAs' => function($result) {
                            return $result->registered_at->format('d M Y');
                        }
                    ])
                    ->editColumn('Total Balance', [
                        'class' => 'right bold',
                        'displayAs' => function($result) {
                            return thousandSeparator($result->balance);
                        }
                    ])
                    ->editColumn('Status', [
                        'class' => 'right bold',
                    ])
                    ->groupBy('Registered At') // Show total of value on specific group. Used with showTotal() enabled.
                    ->showTotal([
                        'Total Balance' => 'point'
                    ])
                    ->stream();
```

**PLEASE TAKE NOTE TO SORT GROUPBY COLUMN VIA QUERY FIRST TO USE THIS GROUP BY METHOD.**

### Output Report With Group By Registered At

[](#output-report-with-group-by-registered-at)

[![Output Report with Group By Grand Total](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-group-by.png)](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-group-by.png)

Wkhtmltopdf Installation
------------------------

[](#wkhtmltopdf-installation)

- Download wkhtmltopdf from
- Change your snappy config located in `/config/snappy.php` (run `php artisan vendor:publish` if `snappy.php` file is not created) to:

```
    'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf', // Or specified your custom wkhtmltopdf path
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

```

Other Method
------------

[](#other-method)

### 1. setPaper($paper = 'a4')

[](#1-setpaperpaper--a4)

**Supported Media Type**: PDF

**Description**: Set Paper Size

**Params**:

- $paper (Default: 'a4')

**Usage:**

```
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->setPaper('a6')
         ->make();
```

### 2. setCss(Array $styles)

[](#2-setcssarray-styles)

**Supported Media Type**: PDF, Excel

**Description**: Set a new custom styles with given selector and style to apply

**Params**:

- Array $styles (Key: $selector, Value: $style)

**Usage:**

```
ExcelReport::of($title, $meta, $queryBuilder, $columns)
            ->editColumn('Registered At', [
                'class' => 'right bolder italic-red'
            ])
            ->setCss([
                '.bolder' => 'font-weight: 800;',
                '.italic-red' => 'color: red;font-style: italic;'
            ])
            ->make();
```

### 3. setOrientation($orientation = 'portrait')

[](#3-setorientationorientation--portrait)

**Supported Media Type**: PDF

**Description**: Set Orientation to Landscape or Portrait

**Params**:

- $orientation (Default: 'portrait')

**Usage:**

```
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->setOrientation('landscape')
         ->make();
```

### 4. withoutManipulation()

[](#4-withoutmanipulation)

**Supported Media Type**: PDF, Excel, CSV

**Description**: Faster generating report, but all columns properties must be matched the selected column from SQL Queries

**Usage:**

```
$queryBuilder = Customer::select(['name', 'age'])->get();
$columns = ['Name', 'Age'];
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->withoutManipulation()
         ->make();
```

### 5. showMeta($value = true)

[](#5-showmetavalue--true)

**Supported Media Type**: PDF, Excel, CSV

**Description**: Show / hide meta attribute on report

**Params**:

- $value (Default: true)

**Usage:**

```
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showMeta(false) // Hide meta
         ->make();
```

### 6. showHeader($value = true)

[](#6-showheadervalue--true)

**Supported Media Type**: PDF, Excel, CSV

**Description**: Show / hide column header on report

**Params**:

- $value (Default: true)

**Usage:**

```
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showHeader(false) // Hide column header
         ->make();
```

### 7. showNumColumn($value = true)

[](#7-shownumcolumnvalue--true)

**Supported Media Type**: PDF, Excel, CSV

**Description**: Show / hide number column on report

**Params**:

- $value (Default: true)

**Usage:**

```
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showNumColumn(false) // Hide number column
         ->make();
```

### 8. simple()

[](#8-simple)

**Supported Media Type**: Excel

**Description**: Generate excel in simple mode (no styling on generated excel report, but faster in generating report)

**Params**:

- None

**Usage:**

```
ExcelReport::of($title, $meta, $queryBuilder, $columns)
         ->simple()
         ->download('filename');
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~28 days

Total

33

Last Release

2572d ago

Major Versions

1.1.0 → 2.0.02019-04-26

PHP version history (2 changes)1.0.0PHP &gt;=5.5.9

2.0.2PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c07613c8ab7356eb1d69752c0f2dc5802aeca61029ea8d3e6b9e58bfacee6af?d=identicon)[coolsam726](/maintainers/coolsam726)

---

Top Contributors

[![Jimmy-JS](https://avatars.githubusercontent.com/u/9798426?v=4)](https://github.com/Jimmy-JS "Jimmy-JS (44 commits)")[![bgarrison25](https://avatars.githubusercontent.com/u/2955550?v=4)](https://github.com/bgarrison25 "bgarrison25 (7 commits)")[![coolsam726](https://avatars.githubusercontent.com/u/5610289?v=4)](https://github.com/coolsam726 "coolsam726 (3 commits)")[![kaptk2](https://avatars.githubusercontent.com/u/466052?v=4)](https://github.com/kaptk2 "kaptk2 (1 commits)")

---

Tags

laravelpdfexcelreportexcel reportpdf report

### Embed Badge

![Health badge](/badges/coolsam-laravel-report-generator/health.svg)

```
[![Health](https://phpackages.com/badges/coolsam-laravel-report-generator/health.svg)](https://phpackages.com/packages/coolsam-laravel-report-generator)
```

###  Alternatives

[jimmyjs/laravel-report-generator

Rapidly Generate Simple Pdf &amp; Excel Report on Laravel 5 (Using Barryvdh/DomPdf or Barryvdh/laravel-snappy &amp; maatwebsite/excel)

580157.4k1](/packages/jimmyjs-laravel-report-generator)[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3542.7M5](/packages/elibyy-tcpdf-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
