$animethemes * @property Collection $artists * @property Collection $resources * @property int $song_id * @property string|null $title * * @method static SongFactory factory(...$parameters) */ class Song extends BaseModel { use Actionable; use Searchable; final public const TABLE = 'songs'; final public const ATTRIBUTE_ID = 'song_id'; final public const ATTRIBUTE_TITLE = 'title'; final public const RELATION_ANIME = 'animethemes.anime'; final public const RELATION_ANIMETHEMES = 'animethemes'; final public const RELATION_ARTISTS = 'artists'; final public const RELATION_RESOURCES = 'resources'; final public const RELATION_THEME_GROUPS = 'animethemes.group'; final public const RELATION_VIDEOS = 'animethemes.animethemeentries.videos'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ Song::ATTRIBUTE_TITLE, ]; /** * The event map for the model. * * Allows for object-based events for native Eloquent events. * * @var array */ protected $dispatchesEvents = [ 'created' => SongCreated::class, 'deleted' => SongDeleted::class, 'deleting' => SongDeleting::class, 'restored' => SongRestored::class, 'updated' => SongUpdated::class, ]; /** * The table associated with the model. * * @var string */ protected $table = Song::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Song::ATTRIBUTE_ID; /** * Get name. * * @return string */ public function getName(): string { if (empty($this->title)) { return strval($this->getKey()); } return $this->title; } /** * Get subtitle. * * @return string */ public function getSubtitle(): string { return $this->animethemes()->count() !== 0 && $this->animethemes->first()->anime !== null ? "{$this->animethemes->first()->anime->getName()} {$this->animethemes->first()->slug}" : $this->getName(); } /** * Get the anime themes that use this song. * * @return HasMany */ public function animethemes(): HasMany { return $this->hasMany(AnimeTheme::class, AnimeTheme::ATTRIBUTE_SONG); } /** * Get the artists included in the performance. * * @return BelongsToMany */ public function artists(): BelongsToMany { return $this->belongsToMany(Artist::class, ArtistSong::TABLE, Song::ATTRIBUTE_ID, Artist::ATTRIBUTE_ID) ->using(ArtistSong::class) ->withPivot(ArtistSong::ATTRIBUTE_AS) ->as(ArtistSongResource::$wrap) ->withTimestamps(); } /** * Get the resources for the song. * * @return BelongsToMany */ public function resources(): BelongsToMany { return $this->belongsToMany(ExternalResource::class, SongResource::TABLE, Song::ATTRIBUTE_ID, ExternalResource::ATTRIBUTE_ID) ->using(SongResource::class) ->withPivot(SongResource::ATTRIBUTE_AS) ->as(SongResourceResource::$wrap) ->withTimestamps(); } }