mirror of
https://github.com/koel/koel
synced 2024-12-24 11:33:05 +00:00
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Song;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class SongResource extends JsonResource
|
|
{
|
|
public function __construct(private Song $song)
|
|
{
|
|
parent::__construct($song);
|
|
}
|
|
|
|
/** @return array<mixed> */
|
|
public function toArray($request): array
|
|
{
|
|
return [
|
|
'type' => 'songs',
|
|
'id' => $this->song->id,
|
|
'title' => $this->song->title,
|
|
'lyrics' => $this->song->lyrics,
|
|
'album_id' => $this->song->album->id,
|
|
'album_name' => $this->song->album->name,
|
|
'artist_id' => $this->song->artist->id,
|
|
'artist_name' => $this->song->artist->name,
|
|
'album_artist_id' => $this->song->album->artist->id,
|
|
'album_artist_name' => $this->song->album->artist->name,
|
|
'album_cover' => $this->song->album->cover,
|
|
'length' => $this->song->length,
|
|
'liked' => (bool) $this->song->liked,
|
|
'play_count' => (int) $this->song->play_count,
|
|
'track' => $this->song->track,
|
|
'disc' => $this->song->disc,
|
|
'created_at' => $this->song->created_at,
|
|
];
|
|
}
|
|
}
|