@@ -82,9 +82,12 @@ public function handle(): void
8282 $ dataTable = app ()->call ([$ oTable , 'dataTable ' ], compact ('query ' ));
8383 $ dataTable ->skipPaging ();
8484
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+ }
8690
87- $ type = Str::startsWith ($ exportType , 'csv ' ) ? 'csv ' : 'xlsx ' ;
8891 $ filename = $ this ->batchId .'. ' .$ type ;
8992
9093 $ path = Storage::disk ($ this ->getDisk ())->path ($ filename );
@@ -108,7 +111,10 @@ public function handle(): void
108111 $ writer ->addRow (Row::fromValues ($ headers ));
109112
110113 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+ }
112118 $ query = $ dataTable ->getFilteredQuery ()->lazy ($ chunkSize );
113119 } else {
114120 $ query = $ dataTable ->getFilteredQuery ()->cursor ();
@@ -123,7 +129,12 @@ public function handle(): void
123129 $ row = Arr::dot ($ row );
124130 }
125131
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+ }
127138
128139 $ columns ->map (function (Column $ column ) use ($ row , &$ cells , $ defaultDateFormat ) {
129140 $ property = $ column ->data ;
@@ -142,15 +153,27 @@ public function handle(): void
142153
143154 switch (true ) {
144155 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+ }
146161 $ format = $ column ->exportFormat ?? '@ ' ;
147162 break ;
148163 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+ }
150169 $ format = $ column ->exportFormat ?? $ defaultDateFormat ;
151170 break ;
152171 case $ this ->wantsNumeric ($ column ):
153- $ cellValue = floatval ($ value );
172+ if ($ value instanceof DateTimeInterface) {
173+ $ cellValue = 0.0 ;
174+ } else {
175+ $ cellValue = floatval ($ value );
176+ }
154177 $ format = $ column ->exportFormat ;
155178 break ;
156179 case $ value instanceof DateTimeInterface:
@@ -174,15 +197,21 @@ public function handle(): void
174197 Storage::disk ($ this ->getS3Disk ())->putFileAs ('' , (new File ($ path )), $ filename );
175198 }
176199
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 ];
179203 $ this ->sendResults ($ data );
180204 }
181205 }
182206
183207 protected function getDisk (): string
184208 {
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 ;
186215 }
187216
188217 /**
@@ -241,7 +270,12 @@ protected function isNumeric($value): bool
241270
242271 protected function getS3Disk (): string
243272 {
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 ;
245279 }
246280
247281 public function sendResults (array $ data ): void
0 commit comments