-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf25e50
commit 4a01faf
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Eloquent Report Generator | ||
|
||
This package can be used to generates reports from Eloquent models | ||
in many formats, such as CSV, PDF, Markdown, and HTML. | ||
|
||
## Installation | ||
|
||
To install, just run the following composer command. | ||
|
||
```bash | ||
composer require langleyfoxall/eloquent-report-generator | ||
``` | ||
|
||
Remember to include the `vendor/autoload.php` file if your framework | ||
does not do this for you. | ||
|
||
## Usage | ||
|
||
See the following code snippet for example usage. | ||
|
||
```php | ||
// CSV report format | ||
$format = (new CsvReportFormat()); | ||
|
||
// 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')); | ||
``` |