Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public function mimeType()
*/
public function lastModified()
{
return Carbon::createFromTimestamp($this->meta('last_modified'), config('app.timezone'));
return Carbon::createFromTimestamp($this->meta('last_modified') ?? 0, config('app.timezone'));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,22 @@ public function it_gets_last_modified_time()
$this->assertEquals(Carbon::parse('2017-01-02 14:35:00')->timestamp, $lastModified->timestamp);
}

#[Test]
public function it_does_not_throw_when_getting_last_modified_and_file_doesnt_exist()
{
// This is really a workaround for an underlying bug.
// It's odd for an asset to not have a corresponding file.
// Once resolved, this test could be removed, although it doesn't hurt by being here.

Storage::fake('test');
// Intentionally do no not create the actual file.

$asset = (new Asset)->container($this->container)->path('foo/test.txt');

$lastModified = $asset->lastModified();
$this->assertInstanceOf(Carbon::class, $lastModified);
}

#[Test]
public function it_generates_and_clears_meta_caches()
{
Expand Down
Loading