|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Providers; |
| 6 | + |
| 7 | +use Carbon\Carbon; |
| 8 | +use Filament\Forms; |
| 9 | +use Filament\Infolists; |
| 10 | +use Filament\Tables; |
| 11 | +use Illuminate\Support\ServiceProvider; |
| 12 | + |
| 13 | +class FilamentServiceProvider extends ServiceProvider |
| 14 | +{ |
| 15 | + public static string $defaultDateDisplayFormat = 'd.m.Y'; |
| 16 | + |
| 17 | + public static string $defaultDateTimeDisplayFormat = 'd.m.Y H:i'; |
| 18 | + |
| 19 | + public static string $defaultDateTimeWithSecondsDisplayFormat = 'd.m.Y H:i:s'; |
| 20 | + |
| 21 | + public static string $defaultTimeDisplayFormat = 'H:i'; |
| 22 | + |
| 23 | + public static string $defaultTimeWithSecondsDisplayFormat = 'H:i:s'; |
| 24 | + |
| 25 | + /** |
| 26 | + * Register services. |
| 27 | + */ |
| 28 | + public function register(): void |
| 29 | + { |
| 30 | + $this->setDateTimeDisplayFormats(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Bootstrap services. |
| 35 | + */ |
| 36 | + public function boot(): void |
| 37 | + { |
| 38 | + // |
| 39 | + } |
| 40 | + |
| 41 | + protected function setDateTimeDisplayFormats(): void |
| 42 | + { |
| 43 | + Tables\Table::$defaultDateDisplayFormat = static::$defaultDateDisplayFormat; |
| 44 | + Tables\Table::$defaultDateTimeDisplayFormat = static::$defaultDateTimeDisplayFormat; |
| 45 | + Tables\Table::$defaultTimeDisplayFormat = static::$defaultTimeDisplayFormat; |
| 46 | + |
| 47 | + Infolists\Infolist::$defaultDateDisplayFormat = static::$defaultDateDisplayFormat; |
| 48 | + Infolists\Infolist::$defaultDateTimeDisplayFormat = static::$defaultDateTimeDisplayFormat; |
| 49 | + Infolists\Infolist::$defaultTimeDisplayFormat = static::$defaultTimeDisplayFormat; |
| 50 | + |
| 51 | + Forms\Components\DateTimePicker::$defaultDateDisplayFormat = static::$defaultDateDisplayFormat; |
| 52 | + Forms\Components\DateTimePicker::$defaultDateTimeDisplayFormat = static::$defaultDateTimeDisplayFormat; |
| 53 | + Forms\Components\DateTimePicker::$defaultDateTimeWithSecondsDisplayFormat = static::$defaultDateTimeWithSecondsDisplayFormat; |
| 54 | + Forms\Components\DateTimePicker::$defaultTimeDisplayFormat = static::$defaultTimeDisplayFormat; |
| 55 | + Forms\Components\DateTimePicker::$defaultTimeWithSecondsDisplayFormat = static::$defaultTimeWithSecondsDisplayFormat; |
| 56 | + |
| 57 | + Carbon::macro('toFormattedDate', fn () => $this->translatedFormat(static::$defaultDateDisplayFormat)); |
| 58 | + Carbon::macro('toFormattedDateTime', fn () => $this->translatedFormat(static::$defaultDateTimeDisplayFormat)); |
| 59 | + Carbon::macro('toFormattedDateTimeWithSeconds', fn () => $this->translatedFormat(static::$defaultDateTimeWithSecondsDisplayFormat)); |
| 60 | + Carbon::macro('toFormattedTime', fn () => $this->translatedFormat(static::$defaultTimeDisplayFormat)); |
| 61 | + } |
| 62 | +} |
0 commit comments