Browse Source

wip exporters

3.x
Andrew Wallo 5 months ago
parent
commit
52ca430463
1 changed files with 20 additions and 4 deletions
  1. 20
    4
      app/Providers/MacroServiceProvider.php

+ 20
- 4
app/Providers/MacroServiceProvider.php View File

491
         });
491
         });
492
 
492
 
493
         ExportColumn::macro('date', function () {
493
         ExportColumn::macro('date', function () {
494
-            $this->formatStateUsing(static function (?Carbon $state) {
495
-                return $state?->toDateString();
494
+            $this->formatStateUsing(static function ($state) {
495
+                if (blank($state)) {
496
+                    return null;
497
+                }
498
+
499
+                try {
500
+                    Carbon::parse($state)->toDateString();
501
+                } catch (\Exception) {
502
+                    return null;
503
+                }
496
             });
504
             });
497
 
505
 
498
             return $this;
506
             return $this;
499
         });
507
         });
500
 
508
 
501
         ExportColumn::macro('dateTime', function () {
509
         ExportColumn::macro('dateTime', function () {
502
-            $this->formatStateUsing(static function (?Carbon $state) {
503
-                return $state?->toDateTimeString();
510
+            $this->formatStateUsing(static function ($state) {
511
+                if (blank($state)) {
512
+                    return null;
513
+                }
514
+
515
+                try {
516
+                    return Carbon::parse($state)->toDateTimeString();
517
+                } catch (\Exception) {
518
+                    return null;
519
+                }
504
             });
520
             });
505
 
521
 
506
             return $this;
522
             return $this;

Loading…
Cancel
Save