koel/app/Http/Resources/ExcerptSearchResource.php

37 lines
917 B
PHP
Raw Normal View History

2022-06-10 10:47:46 +00:00
<?php
namespace App\Http\Resources;
use App\Values\ExcerptSearchResult;
use Illuminate\Http\Resources\Json\JsonResource;
class ExcerptSearchResource extends JsonResource
{
public const JSON_STRUCTURE = [
'songs' => [
SongResource::JSON_STRUCTURE,
],
'artists' => [
ArtistResource::JSON_STRUCTURE,
],
'albums' => [
AlbumResource::JSON_STRUCTURE,
],
];
2024-04-18 14:36:28 +00:00
public function __construct(private readonly ExcerptSearchResult $result)
2022-06-10 10:47:46 +00:00
{
parent::__construct($result);
}
/** @return array<mixed> */
public function toArray($request): array
{
return [
'songs' => SongResource::collection($this->result->songs),
'artists' => ArtistResource::collection($this->result->artists),
'albums' => AlbumResource::collection($this->result->albums),
];
}
}