瀏覽代碼

wip exporters

3.x
Andrew Wallo 3 月之前
父節點
當前提交
52ca430463
共有 1 個檔案被更改,包括 20 行新增4 行删除
  1. 20
    4
      app/Providers/MacroServiceProvider.php

+ 20
- 4
app/Providers/MacroServiceProvider.php 查看文件

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…
取消
儲存