Skip to content

Commit 2118155

Browse files
marcusmooresnipe
authored andcommitted
Fix bug in getImageUrl method
1 parent ba4f5bb commit 2118155

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/Models/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public function getImageUrl()
656656
return Storage::disk('public')->url(app('assets_upload_path').e($this->image));
657657
} elseif ($this->model && ! empty($this->model->image)) {
658658
return Storage::disk('public')->url(app('models_upload_path').e($this->model->image));
659-
} elseif ($this->model->category && ! empty($this->model->category->image)) {
659+
} elseif ($this->model?->category && ! empty($this->model->category->image)) {
660660
return Storage::disk('public')->url(app('categories_upload_path').e($this->model->category->image));
661661
}
662662

tests/Unit/AssetTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ public function testGetImageUrlMethod()
239239
$category->save();
240240

241241
$this->assertFalse($asset->refresh()->getImageUrl());
242+
243+
// handles case where model does not exist
244+
$asset->model_id = 9999999;
245+
$asset->forceSave();
246+
247+
$this->assertFalse($asset->refresh()->getImageUrl());
242248
}
243249
}

0 commit comments

Comments
 (0)