D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
re-viewers.com
/
app
/
Http
/
Resources
/
Filename :
ProductResource.php
back
Copy
<?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ProductResource extends JsonResource { public function toArray($request): array { return [ 'id' => $this->id, 'title' => $this->product_title, 'description' => $this->product_desc, 'image' => $this->product_image ? asset('images/thumbs/' . $this->product_image) : null, 'views' => $this->total_views, 'rate_avg' => $this->rate_avg, 'total_rate' => $this->total_rate, 'user_rating' => $this->user_rating ?? null, 'featured' => (bool) $this->featured, // العلاقات 'category' => new CategoryResource($this->whenLoaded('category')), 'subcategory' => new CategoryResource($this->whenLoaded('subcategory')), 'subsubcategory' => new CategoryResource($this->whenLoaded('subsubcategory')), // التعليقات 'comments' => CommentResource::collection($this->whenLoaded('comments')), 'created_at' => $this->created_at?->toDateTimeString(), 'updated_at' => $this->updated_at?->toDateTimeString(), ]; } }