koel/app/Http/Resources/GenreResource.php

33 lines
674 B
PHP
Raw Normal View History

2022-10-21 20:06:43 +00:00
<?php
namespace App\Http\Resources;
use App\Values\Genre;
use Illuminate\Http\Resources\Json\JsonResource;
class GenreResource extends JsonResource
{
public const JSON_STRUCTURE = [
'type',
'name',
'song_count',
'length',
];
2024-04-18 14:36:28 +00:00
public function __construct(private readonly Genre $genre)
2022-10-21 20:06:43 +00:00
{
parent::__construct($genre);
}
/** @return array<mixed> */
public function toArray($request): array
{
return [
'type' => 'genres',
'name' => $this->genre->name,
'song_count' => $this->genre->songCount,
'length' => $this->genre->length,
];
}
}