<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ProductResource 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 parent::toArray($request);
        $data= [
            'id'=> $this->ID,
            // 'store_id'=> $this->store_id,
            'title'=> $this->post_title,
            'description'=> str_replace(['\n', '\t'], '', strip_tags( nl2br($this->post_content) ) ),
            // 'url'=> $this->url,
            'image'=> $this->image,
            'price'=> (float)$this->price,
            'categories'=> CategoryResource::collection($this->taxonomies),
        ];

        return $data;
    }
}
