Skip to content

Commit ad33864

Browse files
committed
Fix TypeError when asset last_modified meta is null
1 parent 3141447 commit ad33864

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/Assets/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public function mimeType()
601601
*/
602602
public function lastModified()
603603
{
604-
return Carbon::createFromTimestamp($this->meta('last_modified'), config('app.timezone'));
604+
return Carbon::createFromTimestamp($this->meta('last_modified') ?? 0, config('app.timezone'));
605605
}
606606

607607
/**

tests/Assets/AssetTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,22 @@ public function it_gets_last_modified_time()
663663
$this->assertEquals(Carbon::parse('2017-01-02 14:35:00')->timestamp, $lastModified->timestamp);
664664
}
665665

666+
#[Test]
667+
public function it_returns_epoch_when_last_modified_meta_is_null()
668+
{
669+
Storage::fake('test');
670+
Storage::disk('test')->put('foo/test.txt', '');
671+
Storage::disk('test')->put('foo/.meta/test.txt.yaml', YAML::dump([
672+
'data' => [],
673+
]));
674+
675+
$asset = (new Asset)->container($this->container)->path('foo/test.txt');
676+
677+
$lastModified = $asset->lastModified();
678+
$this->assertInstanceOf(Carbon::class, $lastModified);
679+
$this->assertEquals(0, $lastModified->timestamp);
680+
}
681+
666682
#[Test]
667683
public function it_generates_and_clears_meta_caches()
668684
{

0 commit comments

Comments
 (0)