Adds latest episode api endpoint and some other minor modifications.

This commit is contained in:
2025-07-27 16:44:50 +00:00
parent 97b018f2bc
commit 667f0acd83
30 changed files with 3007 additions and 3336 deletions

View File

@@ -33,4 +33,27 @@ class Podcast extends Model
return $this->hasManyThrough(Artist::class, Episode::class);
}
public function latestEpisode()
{
return $this->hasOne(Episode::class)
->where('published', true)
->orderBy('episode_number', 'desc');
}
public function latestArtwork()
{
// this follows the hasOneThrough from Episode → Artwork
return $this->hasOneThrough(
Artwork::class, // final model
Episode::class, // intermediate
'podcast_id', // FK on episodes
'id', // PK on artworks
'id', // PK on podcasts
'artwork_id' // FK on episodes → artworks
)
->where('episodes.published', true)
->orderBy('episodes.episode_number', 'desc');
}
}