InfluxOW/laravel_ddd_ecommerce

View on GitHub
app/Components/Attributable/Http/Resources/AttributeValueResource.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Components\Attributable\Http\Resources;

use App\Components\Attributable\Models\AttributeValue;
use Illuminate\Http\Resources\Json\JsonResource;
use JetBrains\PhpStorm\ArrayShape;

final class AttributeValueResource extends JsonResource
{
    #[ArrayShape(['value' => 'string|int|bool|float', 'attribute' => AttributeResource::class])]
    public function toArray($request): array
    {
        /** @var AttributeValue $value */
        $value = $this->resource;

        return [
            'value' => $value->value,
            'attribute' => AttributeResource::make($value->attribute),
        ];
    }
}