Skip to content

Commit 76c782e

Browse files
committed
Fix CreatedAt / UpdatedAt on record is null
1 parent e77261c commit 76c782e

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
],
1818
"require": {
1919
"php": "^8.0",
20-
"filament/filament": "^2.9",
21-
"filament/forms": "^2.9",
20+
"filament/filament": "^2.10",
21+
"filament/forms": "^2.10",
2222
"illuminate/contracts": "^8.73",
2323
"spatie/laravel-package-tools": "^1.9.2"
2424
},

src/Forms/CreatedAt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public static function make(): Placeholder
1010
{
1111
return Placeholder::make('created_at')
1212
->label(tr('time.created_at'))
13-
->content(fn ($record): string => $record->created_at ? $record->created_at->diffForHumans() : '-');
13+
->content(fn ($record): string => $record?->created_at ? $record->created_at->diffForHumans() : '-');
1414
}
1515
}

src/Forms/UpdatedAt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public static function make(): Placeholder
1010
{
1111
return Placeholder::make('updated_at')
1212
->label(tr('time.updated_at'))
13-
->content(fn ($record): string => $record->updated_at ? $record->updated_at->diffForHumans() : '-');
13+
->content(fn ($record): string => $record?->updated_at ? $record->updated_at->diffForHumans() : '-');
1414
}
1515
}

tests/Forms/CreatedAtTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
use function Spatie\PestPluginTestTime\testTime;
1010

11+
it('can return a dash if the record is null', function () {
12+
TestableForm::$formSchema = [
13+
CreatedAt::make(),
14+
];
15+
16+
testTime()->freeze();
17+
18+
$component = Livewire::test(TestableForm::class, [
19+
'record' => null,
20+
]);
21+
22+
$component
23+
->assertSet('record.created_at', null)
24+
->assertSee('-');
25+
});
26+
1127
it('can return a dash if the created at time is null', function () {
1228
TestableForm::$formSchema = [
1329
CreatedAt::make(),

tests/Forms/UpdatedAtTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
use function Spatie\PestPluginTestTime\testTime;
1010

11+
it('can return a dash if the record is null', function () {
12+
TestableForm::$formSchema = [
13+
UpdatedAt::make(),
14+
];
15+
16+
testTime()->freeze();
17+
18+
$component = Livewire::test(TestableForm::class, [
19+
'record' => null,
20+
]);
21+
22+
$component
23+
->assertSet('record.updated_at', null)
24+
->assertSee('-');
25+
});
26+
1127
it('can return a dash if the updated at time is null', function () {
1228
TestableForm::$formSchema = [
1329
UpdatedAt::make(),

0 commit comments

Comments
 (0)