Skip to content

Commit b845e8f

Browse files
v-Woodyjasonvarga
andauthored
[6.x] Fix TypeError when asset last_modified meta is null (#14530)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 5809912 commit b845e8f

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_does_not_throw_when_getting_last_modified_and_file_doesnt_exist()
668+
{
669+
// This is really a workaround for an underlying bug.
670+
// It's odd for an asset to not have a corresponding file.
671+
// Once resolved, this test could be removed, although it doesn't hurt by being here.
672+
673+
Storage::fake('test');
674+
// Intentionally do no not create the actual file.
675+
676+
$asset = (new Asset)->container($this->container)->path('foo/test.txt');
677+
678+
$lastModified = $asset->lastModified();
679+
$this->assertInstanceOf(Carbon::class, $lastModified);
680+
}
681+
666682
#[Test]
667683
public function it_generates_and_clears_meta_caches()
668684
{

0 commit comments

Comments
 (0)