Edit File: ProductResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; use App\Http\Resources\FeaturesResource; use App\Http\Resources\GroupResource; use App\Http\Resources\ProductAdditiveCategoryResource; use App\Models\ProductGroup; class ProductResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $productfeatures = $this->productfeatures; if($this->type == 'simple'){ $group = new GroupResource($this->groups()->first()); }else{ $group = ['id'=>0,'price'=>'0','qty'=>0]; } $product_additive_categories = $this->store?->productAdditiveCategories; return [ 'id' => $this->id, 'image' => $this->image?$this->imagePath:'', 'name' => $this->name??'', 'desc' => $this->desc??'', 'type' => $this->type??'', 'display_price' => $this->display_price()??0, 'features' => FeaturesResource::collection($productfeatures), 'group' => $group, 'product_additive_categories' => ProductAdditiveCategoryResource::collection($product_additive_categories), ]; } }
Back to File Manager