From e7b60d9aaf3283710b4a12910632dc4b02244bde Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 19 Aug 2021 18:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=AE=BF=E9=97=AE=E5=99=A8?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9=E5=99=A8=E7=9A=84=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Product.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index 34ad683..64de22d 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -4,7 +4,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Facades\Storage; /** * 供应商产品 @@ -21,12 +20,11 @@ class Product extends BaseModel // 获取所有产品图片 public function getPicturesAttribute($value): array { - $pictures = $value ? json_decode($value, true) : []; - foreach ($pictures as &$v) { - $v = Storage::disk('public')->url($v); + if (is_string($value)) { + $value = $value ? json_decode($value, true) : []; } $this->append('picture'); - return $pictures; + return $value ?? []; } // 获取第一张产品图片 @@ -35,17 +33,6 @@ class Product extends BaseModel return $this->pictures[0] ?? ''; } - //保存图片时去掉域名 - public function setPicturesAttribute($value) - { - if (is_array($value)) { - foreach ($value as &$v) { - $v = str_replace(Storage::disk('public')->url(''), '', $v); - } - $this->attributes['pictures'] = json_encode($value); - } - } - public function supplier() { return $this->belongsTo(Supplier::class);