修复产品图片不存在 系统报错
This commit is contained in:
parent
171b1a4b05
commit
14be551526
|
|
@ -12,6 +12,7 @@ class ProductResource extends JsonResource
|
|||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
|
|
@ -20,7 +21,7 @@ class ProductResource extends JsonResource
|
|||
$data = [
|
||||
'id' => $this->id,
|
||||
'images' => array_map(function ($image) {
|
||||
return thumbnail($image);
|
||||
return image_resize($image);
|
||||
}, $this->images ?? []),
|
||||
'name' => $this->description->name ?? '',
|
||||
'price_formatted' => currency_format($masterSku->price),
|
||||
|
|
|
|||
|
|
@ -266,17 +266,6 @@ function current_customer(): ?Customer
|
|||
return auth()->guard(Customer::AUTH_GUARD)->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缩略图
|
||||
*
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
function thumbnail($path): string
|
||||
{
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取语言列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ class ImageService
|
|||
{
|
||||
$this->image = $image ?: self::PLACEHOLDER_IMAGE;
|
||||
$this->imagePath = public_path($this->image);
|
||||
if (!file_exists($this->imagePath)) {
|
||||
$this->image = self::PLACEHOLDER_IMAGE;
|
||||
$this->imagePath = public_path($this->image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue