2022-06-10 10:47:46 +00:00
|
|
|
<?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,
|
2024-01-04 10:24:40 +00:00
|
|
|
'owner_id' => $this->song->owner_id,
|
2022-06-10 10:47:46 +00:00
|
|
|
'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,
|
2022-10-12 09:27:35 +00:00
|
|
|
'album_artist_id' => $this->song->album_artist->id,
|
|
|
|
'album_artist_name' => $this->song->album_artist->name,
|
2022-06-10 10:47:46 +00:00
|
|
|
'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,
|
2022-09-23 06:21:29 +00:00
|
|
|
'genre' => $this->song->genre,
|
|
|
|
'year' => $this->song->year,
|
2024-01-08 22:21:21 +00:00
|
|
|
'is_public' => $this->song->is_public,
|
2022-06-10 10:47:46 +00:00
|
|
|
'created_at' => $this->song->created_at,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|