InfluxOW/laravel_ddd_ecommerce

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

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Components\Attributable\Http\Resources;

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

final class AttributeResource extends JsonResource
{
    #[ArrayShape(['slug' => 'string', 'title' => 'string', 'values_type' => 'string'])]
    public function toArray($request): array
    {
        /** @var Attribute $attribute */
        $attribute = $this->resource;

        return [
            'slug' => $attribute->slug,
            'title' => $attribute->title,
            'values_type' => $attribute->values_type->responseValueType()->name,
        ];
    }
}