koel/app/Http/Resources/CollaborativeSongResource.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2024-01-18 11:13:05 +00:00
<?php
namespace App\Http\Resources;
2024-01-24 22:39:47 +00:00
use App\Values\PlaylistCollaborator;
2024-01-18 11:13:05 +00:00
use Carbon\Carbon;
class CollaborativeSongResource extends SongResource
{
public const JSON_STRUCTURE = SongResource::JSON_STRUCTURE + [
'collaboration' => [
'user' => PlaylistCollaboratorResource::JSON_STRUCTURE,
'added_at',
'fmt_added_at',
],
];
2024-01-18 11:13:05 +00:00
/** @return array<mixed> */
public function toArray($request): array
{
return array_merge(parent::toArray($request), [
'collaboration' => [
2024-01-24 22:39:47 +00:00
'user' => PlaylistCollaboratorResource::make(
PlaylistCollaborator::make(
$this->song->collaborator_id,
$this->song->collaborator_name,
gravatar($this->song->collaborator_email),
),
),
2024-01-18 11:13:05 +00:00
'added_at' => $this->song->added_at,
'fmt_added_at' => $this->song->added_at ? Carbon::make($this->song->added_at)->diffForHumans() : null,
],
]);
}
}