fixed placeholder

This commit is contained in:
Edward Yang 2022-07-12 20:04:10 +08:00
parent 43c7832832
commit f5c980714a
2 changed files with 4 additions and 2 deletions

View File

@ -18,14 +18,16 @@ class ImageService
private $image;
private $imagePath;
const PLACEHOLDER_IMAGE = 'catalog/placeholder.png';
/**
* @param string $image
* @throws \Exception
*/
public function __construct(string $image)
{
$this->image = $image;
$imagePath = public_path($image);
$this->image = $image ?: self::PLACEHOLDER_IMAGE;
$imagePath = public_path($this->image);
if (!file_exists($imagePath)) {
throw new \Exception("图片不存在");
}

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB