添加商品详情接口显示商品特点
parent
064b011e49
commit
9d6acd9df8
|
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue