@@ -82,9 +82,12 @@ public function handle(): void
82
82
$ dataTable = app ()->call ([$ oTable , 'dataTable ' ], compact ('query ' ));
83
83
$ dataTable ->skipPaging ();
84
84
85
- $ exportType = strtolower (strval (request ('exportType ' )));
85
+ $ type = 'xlsx ' ;
86
+ $ exportType = request ('export_type ' , 'xlsx ' );
87
+ if (is_string ($ exportType )) {
88
+ $ type = Str::of ($ exportType )->startsWith ('csv ' ) ? 'csv ' : 'xlsx ' ;
89
+ }
86
90
87
- $ type = Str::startsWith ($ exportType , 'csv ' ) ? 'csv ' : 'xlsx ' ;
88
91
$ filename = $ this ->batchId .'. ' .$ type ;
89
92
90
93
$ path = Storage::disk ($ this ->getDisk ())->path ($ filename );
@@ -108,7 +111,10 @@ public function handle(): void
108
111
$ writer ->addRow (Row::fromValues ($ headers ));
109
112
110
113
if ($ this ->usesLazyMethod ()) {
111
- $ chunkSize = intval (config ('datatables-export.chunk ' , 1000 ));
114
+ $ chunkSize = 1_000 ;
115
+ if (is_int (config ('datatables-export.chunk ' ))) {
116
+ $ chunkSize = config ('datatables-export.chunk ' );
117
+ }
112
118
$ query = $ dataTable ->getFilteredQuery ()->lazy ($ chunkSize );
113
119
} else {
114
120
$ query = $ dataTable ->getFilteredQuery ()->cursor ();
@@ -123,7 +129,12 @@ public function handle(): void
123
129
$ row = Arr::dot ($ row );
124
130
}
125
131
126
- $ defaultDateFormat = strval (config ('datatables-export.default_date_format ' , 'yyyy-mm-dd ' ));
132
+ $ defaultDateFormat = 'yyyy-mm-dd ' ;
133
+ if (config ('datatables-export.default_date_format ' )
134
+ && is_string (config ('datatables-export.default_date_format ' ))
135
+ ) {
136
+ $ defaultDateFormat = config ('datatables-export.default_date_format ' );
137
+ }
127
138
128
139
$ columns ->map (function (Column $ column ) use ($ row , &$ cells , $ defaultDateFormat ) {
129
140
$ property = $ column ->data ;
@@ -142,15 +153,27 @@ public function handle(): void
142
153
143
154
switch (true ) {
144
155
case $ this ->wantsText ($ column ):
145
- $ cellValue = strval ($ value );
156
+ if ($ value instanceof DateTimeInterface) {
157
+ $ cellValue = $ value ->format ($ defaultDateFormat );
158
+ } else {
159
+ $ cellValue = strval ($ value );
160
+ }
146
161
$ format = $ column ->exportFormat ?? '@ ' ;
147
162
break ;
148
163
case $ this ->wantsDateFormat ($ column ):
149
- $ cellValue = $ value ? DateHelper::toExcel (Carbon::parse (strval ($ value ))) : '' ;
164
+ if ($ value instanceof DateTimeInterface) {
165
+ $ cellValue = DateHelper::toExcel ($ value );
166
+ } else {
167
+ $ cellValue = $ value ? DateHelper::toExcel (Carbon::parse (strval ($ value ))) : '' ;
168
+ }
150
169
$ format = $ column ->exportFormat ?? $ defaultDateFormat ;
151
170
break ;
152
171
case $ this ->wantsNumeric ($ column ):
153
- $ cellValue = floatval ($ value );
172
+ if ($ value instanceof DateTimeInterface) {
173
+ $ cellValue = 0.0 ;
174
+ } else {
175
+ $ cellValue = floatval ($ value );
176
+ }
154
177
$ format = $ column ->exportFormat ;
155
178
break ;
156
179
case $ value instanceof DateTimeInterface:
@@ -174,15 +197,21 @@ public function handle(): void
174
197
Storage::disk ($ this ->getS3Disk ())->putFileAs ('' , (new File ($ path )), $ filename );
175
198
}
176
199
177
- if (request ('emailTo ' )) {
178
- $ data = ['email ' => urldecode (strval (request ('emailTo ' ))), 'path ' => $ path ];
200
+ $ emailTo = request ('emailTo ' );
201
+ if ($ emailTo && is_string ($ emailTo )) {
202
+ $ data = ['email ' => urldecode ($ emailTo ), 'path ' => $ path ];
179
203
$ this ->sendResults ($ data );
180
204
}
181
205
}
182
206
183
207
protected function getDisk (): string
184
208
{
185
- return strval (config ('datatables-export.disk ' , 'local ' ));
209
+ $ disk = 'local ' ;
210
+ if (is_string (config ('datatables-export.disk ' ))) {
211
+ $ disk = config ('datatables-export.disk ' );
212
+ }
213
+
214
+ return $ disk ;
186
215
}
187
216
188
217
/**
@@ -241,7 +270,12 @@ protected function isNumeric($value): bool
241
270
242
271
protected function getS3Disk (): string
243
272
{
244
- return strval (config ('datatables-export.s3_disk ' , '' ));
273
+ $ disk = '' ;
274
+ if (config ('datatables-export.s3_disk ' ) && is_string (config ('datatables-export.s3_disk ' ))) {
275
+ $ disk = config ('datatables-export.s3_disk ' );
276
+ }
277
+
278
+ return $ disk ;
245
279
}
246
280
247
281
public function sendResults (array $ data ): void
0 commit comments