@@ -31,7 +31,8 @@ Also, You can use `PdfReport`, `ExcelReport` or `CSVReport` facade for shorter c
31
31
// PdfReport Aliases
32
32
use PdfReport;
33
33
34
- public function displayReport(Request $request) {
34
+ public function displayReport(Request $request)
35
+ {
35
36
// Retrieve any filters
36
37
$fromDate = $request->input('from_date');
37
38
$toDate = $request->input('to_date');
@@ -43,20 +44,28 @@ public function displayReport(Request $request) {
43
44
// For displaying filters description on header
44
45
$meta = [
45
46
'Registered on' => $fromDate . ' To ' . $toDate,
46
- 'Sort By' => $sortBy
47
+ 'Sort By' => $sortBy
47
48
];
48
49
49
50
// 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);
53
61
54
62
// Set Column to be displayed
55
63
$columns = [
56
64
'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
58
67
'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
60
69
return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
61
70
}
62
71
];
@@ -73,25 +82,30 @@ public function displayReport(Request $request) {
73
82
- make() : Will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download()
74
83
*/
75
84
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
94
107
}
108
+
95
109
```
96
110
97
111
Note: For downloading to excel, just change ` PdfReport ` facade to ` ExcelReport ` facade no more modifications
@@ -146,7 +160,7 @@ $columns = [
146
160
### Example Code With Group By
147
161
Or, you can total all records by group using ` groupBy ` method
148
162
``` php
149
- ...
163
+ // ...
150
164
// Do some querying..
151
165
$queryBuilder = User::select(['name', 'balance', 'registered_at'])
152
166
->whereBetween('registered_at', [$fromDate, $toDate])
@@ -161,26 +175,28 @@ Or, you can total all records by group using `groupBy` method
161
175
return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
162
176
}
163
177
];
178
+
164
179
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
+
184
200
```
185
201
186
202
** 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)
217
233
** Usage:**
218
234
``` php
219
235
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();
228
244
```
229
245
230
246
### 3. setOrientation($orientation = 'portrait')
0 commit comments