diff --git a/resources/lang/en/translations.php b/resources/lang/en/translations.php index f80bb71..4bb478a 100644 --- a/resources/lang/en/translations.php +++ b/resources/lang/en/translations.php @@ -4,5 +4,6 @@ 'time' => [ 'created_at' => 'Created at', 'updated_at' => 'Updated at', + 'deleted_at' => 'Deleted at', ] ]; diff --git a/src/Forms/CreatedAt.php b/src/Forms/CreatedAt.php index b2149c9..38ac04b 100644 --- a/src/Forms/CreatedAt.php +++ b/src/Forms/CreatedAt.php @@ -6,10 +6,8 @@ class CreatedAt { - public static function make(): Placeholder + public static function make(string $label = null): Placeholder { - return Placeholder::make('created_at') - ->label(tr('time.created_at')) - ->content(fn ($record): string => $record?->created_at ? $record->created_at->diffForHumans() : '-'); + return Timestamp::make('created_at', $label); } } diff --git a/src/Forms/DeletedAt.php b/src/Forms/DeletedAt.php new file mode 100644 index 0000000..7129dc1 --- /dev/null +++ b/src/Forms/DeletedAt.php @@ -0,0 +1,13 @@ +label(function () use ($column, $label) { + if ($label) { + return $label; + } + + return match ( $column ) { + 'created_at' => tr('time.created_at'), + 'updated_at' => tr('time.updated_at'), + 'deleted_at' => tr('time.deleted_at'), + default => null, + }; + }) + ->content(fn ($record): string => $record?->$column ? $record->$column->diffForHumans() : '-'); + } +} diff --git a/src/Forms/UpdatedAt.php b/src/Forms/UpdatedAt.php index 63c3ed4..04410fc 100644 --- a/src/Forms/UpdatedAt.php +++ b/src/Forms/UpdatedAt.php @@ -6,10 +6,8 @@ class UpdatedAt { - public static function make(): Placeholder + public static function make(string $label = null): Placeholder { - return Placeholder::make('updated_at') - ->label(tr('time.updated_at')) - ->content(fn ($record): string => $record?->updated_at ? $record->updated_at->diffForHumans() : '-'); + return Timestamp::make('updated_at', $label); } }