From c431ffbb83a83ef71dd1b073382ad00e665175c7 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Thu, 4 Aug 2022 15:12:48 +0800 Subject: [PATCH] show brands --- beike/Services/DesignService.php | 8 +++++--- beike/Shop/Http/Resources/BrandDetail.php | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/beike/Services/DesignService.php b/beike/Services/DesignService.php index 256cd5ee..1a71246d 100644 --- a/beike/Services/DesignService.php +++ b/beike/Services/DesignService.php @@ -11,7 +11,9 @@ namespace Beike\Services; +use Beike\Repositories\BrandRepo; use Beike\Repositories\ProductRepo; +use Beike\Shop\Http\Resources\BrandDetail; use Illuminate\Support\Str; class DesignService @@ -79,10 +81,10 @@ class DesignService */ private static function handleBrand($content): array { - $brands = $content['brands']; + $brandIds = $content['brands'] ?? []; + $brands = BrandDetail::collection(BrandRepo::getListByIds($brandIds))->jsonSerialize(); - - $content['brands'] = []; + $content['brands'] = $brands; $content['title'] = $content['title'][locale()]; return $content; } diff --git a/beike/Shop/Http/Resources/BrandDetail.php b/beike/Shop/Http/Resources/BrandDetail.php index 5a188729..e37f6086 100644 --- a/beike/Shop/Http/Resources/BrandDetail.php +++ b/beike/Shop/Http/Resources/BrandDetail.php @@ -15,6 +15,9 @@ use Illuminate\Http\Resources\Json\JsonResource; class BrandDetail extends JsonResource { + /** + * @throws \Exception + */ public function toArray($request): array { return [ @@ -22,6 +25,7 @@ class BrandDetail extends JsonResource 'name' => $this->name, 'logo' => image_resize($this->logo), 'sort_order' => $this->sort_order, + 'url'=> shop_route('brands.show', $this->id), 'first' => $this->first, ]; }