Skip to content

Commit dfa12b4

Browse files
committed
Update readme.md
1 parent 204d511 commit dfa12b4

File tree

1 file changed

+69
-53
lines changed

1 file changed

+69
-53
lines changed

readme.md

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Also, You can use `PdfReport`, `ExcelReport` or `CSVReport` facade for shorter c
3131
// PdfReport Aliases
3232
use PdfReport;
3333

34-
public function displayReport(Request $request) {
34+
public function displayReport(Request $request)
35+
{
3536
// Retrieve any filters
3637
$fromDate = $request->input('from_date');
3738
$toDate = $request->input('to_date');
@@ -43,20 +44,28 @@ public function displayReport(Request $request) {
4344
// For displaying filters description on header
4445
$meta = [
4546
'Registered on' => $fromDate . ' To ' . $toDate,
46-
'Sort By' => $sortBy
47+
'Sort By' => $sortBy
4748
];
4849

4950
// Do some querying..
50-
$queryBuilder = User::select(['name', 'balance', 'registered_at'])
51-
->whereBetween('registered_at', [$fromDate, $toDate])
52-
->orderBy($sortBy);
51+
$queryBuilder = User::select([
52+
'name',
53+
'balance',
54+
'registered_at'
55+
])
56+
->whereBetween('registered_at', [
57+
$fromDate,
58+
$toDate
59+
])
60+
->orderBy($sortBy);
5361

5462
// Set Column to be displayed
5563
$columns = [
5664
'Name' => 'name',
57-
'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
65+
'Registered At',
66+
// if no column_name specified, this will automatically seach for snake_case of column name (will be registered_at) column from query result
5867
'Total Balance' => 'balance',
59-
'Status' => function($result) { // You can do if statement or any action do you want inside this closure
68+
'Status' => function ($result) { // You can do if statement or any action do you want inside this closure
6069
return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
6170
}
6271
];
@@ -73,25 +82,30 @@ public function displayReport(Request $request) {
7382
- make() : Will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download()
7483
*/
7584
return PdfReport::of($title, $meta, $queryBuilder, $columns)
76-
->editColumn('Registered At', [
77-
'displayAs' => function($result) {
78-
return $result->registered_at->format('d M Y');
79-
}
80-
])
81-
->editColumn('Total Balance', [
82-
'displayAs' => function($result) {
83-
return thousandSeparator($result->balance);
84-
}
85-
])
86-
->editColumns(['Total Balance', 'Status'], [
87-
'class' => 'right bold'
88-
])
89-
->showTotal([
90-
'Total Balance' => 'point' // if you want to show dollar sign ($) then use 'Total Balance' => '$'
91-
])
92-
->limit(20)
93-
->stream(); // or download('filename here..') to download pdf
85+
->editColumn('Registered At', [
86+
'displayAs' => function ($result) {
87+
return $result->registered_at->format('d M Y');
88+
}
89+
])
90+
->editColumn('Total Balance', [
91+
'displayAs' => function ($result) {
92+
return thousandSeparator($result->balance);
93+
}
94+
])
95+
->editColumns([
96+
'Total Balance',
97+
'Status'
98+
], [
99+
'class' => 'right bold'
100+
])
101+
->showTotal([
102+
'Total Balance' => 'point'
103+
// if you want to show dollar sign ($) then use 'Total Balance' => '$'
104+
])
105+
->limit(20)
106+
->stream(); // or download('filename here..') to download pdf
94107
}
108+
95109
```
96110

97111
Note: For downloading to excel, just change `PdfReport` facade to `ExcelReport` facade no more modifications
@@ -146,7 +160,7 @@ $columns = [
146160
### Example Code With Group By
147161
Or, you can total all records by group using `groupBy` method
148162
```php
149-
...
163+
// ...
150164
// Do some querying..
151165
$queryBuilder = User::select(['name', 'balance', 'registered_at'])
152166
->whereBetween('registered_at', [$fromDate, $toDate])
@@ -161,26 +175,28 @@ Or, you can total all records by group using `groupBy` method
161175
return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
162176
}
163177
];
178+
164179
return PdfReport::of($title, $meta, $queryBuilder, $columns)
165-
->editColumn('Registered At', [
166-
'displayAs' => function($result) {
167-
return $result->registered_at->format('d M Y');
168-
}
169-
])
170-
->editColumn('Total Balance', [
171-
'class' => 'right bold',
172-
'displayAs' => function($result) {
173-
return thousandSeparator($result->balance);
174-
}
175-
])
176-
->editColumn('Status', [
177-
'class' => 'right bold',
178-
])
179-
->groupBy('Registered At')
180-
->showTotal([
181-
'Total Balance' => 'point'
182-
])
183-
->stream();
180+
->editColumn('Registered At', [
181+
'displayAs' => function ($result) {
182+
return $result->registered_at->format('d M Y');
183+
}
184+
])
185+
->editColumn('Total Balance', [
186+
'class' => 'right bold',
187+
'displayAs' => function ($result) {
188+
return thousandSeparator($result->balance);
189+
}
190+
])
191+
->editColumn('Status', [
192+
'class' => 'right bold',
193+
])
194+
->groupBy('Registered At')
195+
->showTotal([
196+
'Total Balance' => 'point'
197+
])
198+
->stream();
199+
184200
```
185201

186202
**PLEASE TAKE NOTE TO SORT GROUPBY COLUMN VIA QUERY FIRST TO USE THIS GROUP BY METHOD.**
@@ -217,14 +233,14 @@ PdfReport::of($title, $meta, $queryBuilder, $columns)
217233
**Usage:**
218234
```php
219235
ExcelReport::of($title, $meta, $queryBuilder, $columns)
220-
->editColumn('Registered At', [
221-
'class' => 'right bolder italic-red'
222-
])
223-
->setCss([
224-
'.bolder' => 'font-weight: 800;',
225-
'.italic-red' => 'color: red;font-style: italic;'
226-
])
227-
->make();
236+
->editColumn('Registered At', [
237+
'class' => 'right bolder italic-red'
238+
])
239+
->setCss([
240+
'.bolder' => 'font-weight: 800;',
241+
'.italic-red' => 'color: red;font-style: italic;'
242+
])
243+
->make();
228244
```
229245

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

0 commit comments

Comments
 (0)