-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from LukasFreyCZ/feature/generic-timestamp
Feature/generic timestamp
- Loading branch information
Showing
5 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
'time' => [ | ||
'created_at' => 'Created at', | ||
'updated_at' => 'Updated at', | ||
'deleted_at' => 'Deleted at', | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace RalphJSmit\Filament\Components\Forms; | ||
|
||
use Filament\Forms\Components\Placeholder; | ||
|
||
class DeletedAt | ||
{ | ||
public static function make(string $label = null): Placeholder | ||
{ | ||
return Timestamp::make('deleted_at', $label); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace RalphJSmit\Filament\Components\Forms; | ||
|
||
use Filament\Forms\Components\Placeholder; | ||
|
||
class Timestamp | ||
{ | ||
public static function make(string $column, string $label = null): Placeholder | ||
{ | ||
return Placeholder::make($column) | ||
->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() : '-'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters