6
0
Fork 0

添加商品详情接口显示商品特点

release
vine_liutk 2021-12-23 15:54:23 +08:00
parent 064b011e49
commit 9d6acd9df8
2 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Endpoint\Api\Http\Controllers\Product;
use App\Endpoint\Api\Http\Controllers\Controller;
use App\Endpoint\Api\Http\Resources\ProduckSkuResource;
use App\Endpoint\Api\Http\Resources\ProductFeatureResource;
use App\Endpoint\Api\Http\Resources\ProductSkuTinyResource;
use App\Events\ProductSkuViewed;
use App\Helpers\Paginator;
@ -61,7 +62,7 @@ class ProductSkuController extends Controller
$sku = ProductSku::with('buynote')->findOrFail($id);
$spu = ProductSpu::with('specs')->findOrFail($sku->spu_id);
$spu = ProductSpu::with(['specs', 'features'])->findOrFail($sku->spu_id);
// 主商品的规格
$spuSpecs = [];
@ -110,6 +111,7 @@ class ProductSkuController extends Controller
'spu_specs' => $spuSpecs,
'sku' => ProduckSkuResource::make($sku),
'is_collected' => $isCollected,
'features' => ProductFeatureResource::collection($spu->features),
]);
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Endpoint\Api\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductFeatureResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'name' => $this->name,
'icon' => (string) $this->icon,
];
}
}