@@ -8,32 +8,32 @@ |
||
8 | 8 | |
9 | 9 | class ProductResource extends JsonResource |
10 | 10 | { |
11 | - /** |
|
12 | - * Transform the resource into an array. |
|
13 | - * |
|
14 | - * @param \Illuminate\Http\Request $request |
|
15 | - * @return array |
|
16 | - */ |
|
17 | - public function toArray($request) |
|
18 | - { |
|
19 | - return [ |
|
20 | - 'id' => $this->id, |
|
11 | + /** |
|
12 | + * Transform the resource into an array. |
|
13 | + * |
|
14 | + * @param \Illuminate\Http\Request $request |
|
15 | + * @return array |
|
16 | + */ |
|
17 | + public function toArray($request) |
|
18 | + { |
|
19 | + return [ |
|
20 | + 'id' => $this->id, |
|
21 | 21 | 'name' => $this->name, |
22 | - 'slug' => $this->slug, |
|
23 | - 'sku' => $this->hasSku() ? $this->skus()->first()->code : null, |
|
22 | + 'slug' => $this->slug, |
|
23 | + 'sku' => $this->hasSku() ? $this->skus()->first()->code : null, |
|
24 | 24 | 'short_description' => $this->short_description, |
25 | - 'description' => $this->description, |
|
26 | - 'price' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00, |
|
27 | - 'cost' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00, |
|
28 | - 'is_active' => $this->is_active, |
|
29 | - 'category' => [ |
|
30 | - 'id' => $this->category->id, |
|
31 | - 'name' => $this->category->name |
|
32 | - ], |
|
33 | - 'attributes' => AttributeResource::collection($this->attributes)->toArray(app('request')), |
|
34 | - 'variations' => $this->when($this->hasAttributes() && $this->hasSku(), |
|
35 | - VariantResource::collection($this->skus)->toArray(app('request')) |
|
36 | - ) |
|
37 | - ]; |
|
38 | - } |
|
25 | + 'description' => $this->description, |
|
26 | + 'price' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00, |
|
27 | + 'cost' => $this->hasSku() ? number_format($this->skus()->first()->price, 2, '.', '') : 0.00, |
|
28 | + 'is_active' => $this->is_active, |
|
29 | + 'category' => [ |
|
30 | + 'id' => $this->category->id, |
|
31 | + 'name' => $this->category->name |
|
32 | + ], |
|
33 | + 'attributes' => AttributeResource::collection($this->attributes)->toArray(app('request')), |
|
34 | + 'variations' => $this->when($this->hasAttributes() && $this->hasSku(), |
|
35 | + VariantResource::collection($this->skus)->toArray(app('request')) |
|
36 | + ) |
|
37 | + ]; |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |