*/ protected $guarded = []; /** * @var string */ protected $table = 'anidb_info'; /** * Get the title associated with this info. * * @return BelongsTo */ public function title(): BelongsTo { return $this->belongsTo(AnidbTitle::class, 'anidbid'); } /** * Get the releases associated with this anime. * * @return HasMany */ public function releases(): HasMany { return $this->hasMany(Release::class, 'anidbid', 'anidbid'); } /** * Get the picture path. */ public function getPicturePath(): string { return storage_path('covers/anime/'.$this->anidbid.'-cover.webp'); } /** * Check if picture image exists locally. */ public function hasPictureImage(): bool { $path = $this->getPicturePath(); $legacyPath = preg_replace('/\.webp$/', '.jpg', $path); $oldLegacyPath = storage_path('covers/anime/'.$this->anidbid.'.jpg'); return file_exists($path) || (is_string($legacyPath) && file_exists($legacyPath)) || file_exists($oldLegacyPath); } /** * Get the picture URL. */ public function getPictureUrl(): ?string { if (empty($this->picture)) { return null; } // If picture is already a URL, return it if (filter_var($this->picture, FILTER_VALIDATE_URL)) { return $this->picture; } // Otherwise construct the local path if ($this->hasPictureImage()) { return getImageAssetUrl( 'anime', $this->anidbid.'-cover', null, [(string) $this->anidbid] ); } return null; } /** * Get AniDB URL if anidbid exists. */ public function getAnidbUrl(): ?string { if (empty($this->anidbid)) { return null; } return 'https://anidb.net/anime/'.$this->anidbid; } /** * Get AniList URL if anilist_id exists. */ public function getAnilistUrl(): ?string { if (empty($this->anilist_id)) { return null; } return 'https://anilist.co/anime/'.$this->anilist_id; } /** * Get MyAnimeList URL if mal_id exists. */ public function getMalUrl(): ?string { if (empty($this->mal_id)) { return null; } return 'https://myanimelist.net/anime/'.$this->mal_id; } /** * Get MyAnimeList URL if mal_id exists. */ public function getMyAnimeListUrl(): ?string { return $this->getMalUrl(); } /** * Get available external links keyed by provider. * * @return array */ public function getExternalLinks(): array { return array_filter([ 'anidb' => $this->getAnidbUrl(), 'anilist' => $this->getAnilistUrl(), 'myanimelist' => $this->getMyAnimeListUrl(), ]); } /** * Check whether at least one external link exists. */ public function hasExternalLinks(): bool { return $this->getExternalLinks() !== []; } }