{"id":13560943,"url":"https://github.com/Jimmy-JS/laravel-report-generator","last_synced_at":"2025-04-03T16:31:30.727Z","repository":{"id":38848700,"uuid":"90845873","full_name":"Jimmy-JS/laravel-report-generator","owner":"Jimmy-JS","description":"Rapidly Generate Simple Pdf, CSV, \u0026 Excel Report Package on Laravel","archived":false,"fork":false,"pushed_at":"2024-11-15T06:33:16.000Z","size":358,"stargazers_count":575,"open_issues_count":6,"forks_count":154,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-29T19:00:29.888Z","etag":null,"topics":["csv","excel","excelgenerator","laravel","pdf","pdf-report","report"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/jimmyjs/laravel-report-generator","language":"Blade","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jimmy-JS.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-10T09:23:57.000Z","updated_at":"2025-03-25T06:17:13.000Z","dependencies_parsed_at":"2024-08-01T13:16:34.977Z","dependency_job_id":"3847ad5d-5ae8-45a7-9c36-919442b35c08","html_url":"https://github.com/Jimmy-JS/laravel-report-generator","commit_stats":{"total_commits":58,"total_committers":6,"mean_commits":9.666666666666666,"dds":0.2068965517241379,"last_synced_commit":"2e39ea8b328981ae62c89a810989a73734d28019"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimmy-JS%2Flaravel-report-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimmy-JS%2Flaravel-report-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimmy-JS%2Flaravel-report-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimmy-JS%2Flaravel-report-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jimmy-JS","download_url":"https://codeload.github.com/Jimmy-JS/laravel-report-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247037015,"owners_count":20873079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","excel","excelgenerator","laravel","pdf","pdf-report","report"],"created_at":"2024-08-01T13:00:51.047Z","updated_at":"2025-04-03T16:31:29.486Z","avatar_url":"https://github.com/Jimmy-JS.png","language":"Blade","funding_links":[],"categories":["Blade","Packages"],"sub_categories":["Helpers/General"],"readme":"# Laravel Report Generators (PDF, CSV \u0026 Excel)\nRapidly 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))\n\nThis package provides a simple pdf, csv \u0026 excel report generators to speed up your workflow.\nIt also allows you to stream(), download(), or store() the report seamlessly.\n\n## Version\n| Version | Laravel Version | Php Version | Maatwebsite/Excel Ver | Feature\n|------|---------|-------|--------|-------\n| 1.0  | \u003c= 5.6  | \u003c=7.0 | ~2.1.0 | using `chunk()` to handle big data\n| 1.1  | \u003c= 5.6  | \u003c=7.0 | ~2.1.0 | using `cursor()` to handle big data\n| 2.0  | \\\u003e= 5.5 | ^7.0  |  ^3.1  | Using new version of maatwebsite (v3.1)\n\nFind the comparison between `chunk` and `cursor` in [here](https://qiita.com/ryo511/items/ebcd1c1b2ad5addc5c9d)\n\n## Installation\nAdd package to your composer:\n\n    composer require jimmyjs/laravel-report-generator\n\nIf you are running Laravel \u003e 5.5 that's all you need to do. If you are using Laravel \u003c 5.5 add the ServiceProvider to the providers array in config/app.php\n\n    Jimmyjs\\ReportGenerator\\ServiceProvider::class,\n\n**Optionally**, you can add this to your aliases array in config/app.php\n\n    'PdfReport' =\u003e Jimmyjs\\ReportGenerator\\Facades\\PdfReportFacade::class,\n    'ExcelReport' =\u003e Jimmyjs\\ReportGenerator\\Facades\\ExcelReportFacade::class,\n    'CSVReport' =\u003e Jimmyjs\\ReportGenerator\\Facades\\CSVReportFacade::class,\n\n**Optionally**, You can publish the config file (then it will be available in `config/report-generator.php`)\n\n    php artisan vendor:publish --provider=\"Jimmyjs\\ReportGenerator\\ServiceProvider\"\n\nIf you want to generate a pdf report, please install either dompdf / snappy pdf. \nThis package will automatically use snappy pdf. If you want to use dompdf then please change `config/report-generator.php`:\n\n    return [\n        'flush' =\u003e false,\n        'pdfLibrary' =\u003e 'dompdf'\n    ];\n\nFor 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)\n\n### Example Display PDF Code\n```php\nuse PdfReport;\n\npublic function displayReport(Request $request)\n{\n    $fromDate = $request-\u003einput('from_date');\n    $toDate = $request-\u003einput('to_date');\n    $sortBy = $request-\u003einput('sort_by');\n\n    $title = 'Registered User Report'; // Report title\n\n    $meta = [ // For displaying filters description on header\n        'Registered on' =\u003e $fromDate . ' To ' . $toDate,\n        'Sort By' =\u003e $sortBy\n    ];\n\n    $queryBuilder = User::select(['name', 'balance', 'registered_at']) // Do some querying..\n                        -\u003ewhereBetween('registered_at', [$fromDate, $toDate])\n                        -\u003eorderBy($sortBy);\n\n    $columns = [ // Set Column to be displayed\n        'Name' =\u003e 'name',\n        '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\n        'Total Balance' =\u003e 'balance',\n        'Status' =\u003e function($result) { // You can do if statement or any action do you want inside this closure\n            return ($result-\u003ebalance \u003e 100000) ? 'Rich Man' : 'Normal Guy';\n        }\n    ];\n\n    // Generate Report with flexibility to manipulate column class even manipulate column value (using Carbon, etc).\n    return PdfReport::of($title, $meta, $queryBuilder, $columns)\n                    -\u003eeditColumn('Registered At', [ // Change column class or manipulate its data for displaying to report\n                        'displayAs' =\u003e function($result) {\n                            return $result-\u003eregistered_at-\u003eformat('d M Y');\n                        },\n                        'class' =\u003e 'left'\n                    ])\n                    -\u003eeditColumns(['Total Balance', 'Status'], [ // Mass edit column\n                        'class' =\u003e 'right bold'\n                    ])\n                    -\u003eshowTotal([ // 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\n                        'Total Balance' =\u003e 'point' // if you want to show dollar sign ($) then use 'Total Balance' =\u003e '$'\n                    ])\n                    -\u003elimit(20) // Limit record to be showed\n                    -\u003estream(); // other available method: store('path/to/file.pdf') to save to disk, 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()\n}\n```\n\nNote: For downloading to excel / CSV, just change `PdfReport` facade to `ExcelReport` / `CSVReport` facade with no more modifications\n\n### Data Manipulation\n```php\n$columns = [\n    'Name' =\u003e 'name',\n    'Registered At' =\u003e 'registered_at',\n    'Total Balance' =\u003e 'balance',\n    'Status' =\u003e function($customer) { // You can do data manipulation, if statement or any action do you want inside this closure\n        return ($customer-\u003ebalance \u003e 100000) ? 'Rich Man' : 'Normal Guy';\n    }\n];\n```\nWill produce a same result with:\n```php\n$columns = [\n    'Name' =\u003e function($customer) {\n        return $customer-\u003ename;\n    },\n    'Registered At' =\u003e function($customer) {\n        return $customer-\u003eregistered_at;\n    },\n    'Total Balance' =\u003e function($customer) {\n        return $customer-\u003ebalance;\n    },\n    'Status' =\u003e function($customer) { // You can do if statement or any action do you want inside this closure\n        return ($customer-\u003ebalance \u003e 100000) ? 'Rich Man' : 'Normal Guy';\n    }\n];\n```\n### Report Output\n![Report Output with Grand Total](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-total.png)\n\nWith this manipulation, you could do some **eager loading relation** like:\n```php\n$post = Post::with('comments')-\u003ewhere('active', 1);\n\n$columns = [\n    'Post Title' =\u003e function($post) {\n        return $post-\u003etitle;\n    },\n    'Slug' =\u003e 'slug',\n    'Latest Comment' =\u003e function($post) {\n        return $post-\u003ecomments-\u003efirst()-\u003ebody;\n    }\n];\n```\n\n### Example Code With Group By\nOr, you can total all records by group using `groupBy` method\n```php\n    ...\n    // Do some querying..\n    $queryBuilder = User::select(['name', 'balance', 'registered_at'])\n                        -\u003ewhereBetween('registered_at', [$fromDate, $toDate])\n                        -\u003eorderBy('registered_at', 'ASC'); // You should sort groupBy column to use groupBy() Method\n\n    $columns = [ // Set Column to be displayed\n        'Registered At' =\u003e 'registered_at',\n        'Name' =\u003e 'name',\n        'Total Balance' =\u003e 'balance',\n        'Status' =\u003e function($result) { // You can do if statement or any action do you want inside this closure\n            return ($result-\u003ebalance \u003e 100000) ? 'Rich Man' : 'Normal Guy';\n        }\n    ];\n\n    return PdfReport::of($title, $meta, $queryBuilder, $columns)\n                    -\u003eeditColumn('Registered At', [\n                        'displayAs' =\u003e function($result) {\n                            return $result-\u003eregistered_at-\u003eformat('d M Y');\n                        }\n                    ])\n                    -\u003eeditColumn('Total Balance', [\n                        'class' =\u003e 'right bold',\n                        'displayAs' =\u003e function($result) {\n                            return thousandSeparator($result-\u003ebalance);\n                        }\n                    ])\n                    -\u003eeditColumn('Status', [\n                        'class' =\u003e 'right bold',\n                    ])\n                    -\u003egroupBy('Registered At') // Show total of value on specific group. Used with showTotal() enabled.\n                    -\u003eshowTotal([\n                        'Total Balance' =\u003e 'point'\n                    ])\n                    -\u003estream();\n```\n\n**PLEASE TAKE NOTE TO SORT GROUPBY COLUMN VIA QUERY FIRST TO USE THIS GROUP BY METHOD.**\n\n### Output Report With Group By Registered At\n![Output Report with Group By Grand Total](https://raw.githubusercontent.com/Jimmy-JS/laravel-report-generator/master/screenshots/report-with-group-by.png)\n\n\n## Wkhtmltopdf Installation\n* Download wkhtmltopdf from https://wkhtmltopdf.org/downloads.html\n* Change your snappy config located in `/config/snappy.php` (run `php artisan vendor:publish` if `snappy.php` file is not created) to:\n```\n    'pdf' =\u003e array(\n        'enabled' =\u003e true,\n        'binary'  =\u003e '/usr/local/bin/wkhtmltopdf', // Or specified your custom wkhtmltopdf path\n        'timeout' =\u003e false,\n        'options' =\u003e array(),\n        'env'     =\u003e array(),\n    ),\n```\n\n\n## Other Method\n\n### 1. setPaper($paper = 'a4')\n**Supported Media Type**: PDF\n\n**Description**: Set Paper Size\n\n**Params**:\n* $paper (Default: 'a4')\n\n**Usage:**\n```php\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003esetPaper('a6')\n         -\u003emake();\n```\n\n### 2. setCss(Array $styles)\n**Supported Media Type**: PDF, Excel\n\n**Description**: Set a new custom styles with given selector and style to apply\n\n**Params**:\n* Array $styles (Key: $selector, Value: $style)\n\n**Usage:**\n```php\nExcelReport::of($title, $meta, $queryBuilder, $columns)\n            -\u003eeditColumn('Registered At', [\n                'class' =\u003e 'right bolder italic-red'\n            ])\n            -\u003esetCss([\n                '.bolder' =\u003e 'font-weight: 800;',\n                '.italic-red' =\u003e 'color: red;font-style: italic;'\n            ])\n            -\u003emake();\n```\n\n### 3. setOrientation($orientation = 'portrait')\n**Supported Media Type**: PDF\n\n**Description**: Set Orientation to Landscape or Portrait\n\n**Params**:\n* $orientation (Default: 'portrait')\n\n**Usage:**\n```php\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003esetOrientation('landscape')\n         -\u003emake();\n```\n\n### 4. withoutManipulation()\n**Supported Media Type**: PDF, Excel, CSV\n\n**Description**: Faster generating report, but all columns properties must be matched the selected column from SQL Queries\n\n**Usage:**\n```php\n$queryBuilder = Customer::select(['name', 'age'])-\u003eget();\n$columns = ['Name', 'Age'];\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003ewithoutManipulation()\n         -\u003emake();\n```\n\n### 5. showMeta($value = true)\n**Supported Media Type**: PDF, Excel, CSV\n\n**Description**: Show / hide meta attribute on report\n\n**Params**:\n* $value (Default: true)\n\n**Usage:**\n```php\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003eshowMeta(false) // Hide meta\n         -\u003emake();\n```\n\n### 6. showHeader($value = true)\n**Supported Media Type**: PDF, Excel, CSV\n\n**Description**: Show / hide column header on report\n\n**Params**:\n* $value (Default: true)\n\n**Usage:**\n```php\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003eshowHeader(false) // Hide column header\n         -\u003emake();\n```\n\n### 7. showNumColumn($value = true)\n**Supported Media Type**: PDF, Excel, CSV\n\n**Description**: Show / hide number column on report\n\n**Params**:\n* $value (Default: true)\n\n**Usage:**\n```php\nPdfReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003eshowNumColumn(false) // Hide number column\n         -\u003emake();\n```\n\n### 8. simple()\n**Supported Media Type**: Excel\n\n**Description**: Generate excel in simple mode (no styling on generated excel report, but faster in generating report)\n\n**Params**:\n* None\n\n**Usage:**\n```php\nExcelReport::of($title, $meta, $queryBuilder, $columns)\n         -\u003esimple()\n         -\u003edownload('filename');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJimmy-JS%2Flaravel-report-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJimmy-JS%2Flaravel-report-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJimmy-JS%2Flaravel-report-generator/lists"}