$animesynonyms * @property Collection $animethemes * @property DiscordThread|null $discordthread * @property Collection $externalentries * @property Collection $images * @property AnimeMediaFormat $media_format * @property string $name * @property Collection $resources * @property AnimeSeason|null $season * @property Collection $series * @property string $slug * @property Collection $studios * @property string|null $synopsis * @property int|null $year * * @method static AnimeFactory factory(...$parameters) */ class Anime extends BaseModel { use Searchable; final public const TABLE = 'anime'; final public const ATTRIBUTE_ID = 'anime_id'; final public const ATTRIBUTE_MEDIA_FORMAT = 'media_format'; final public const ATTRIBUTE_NAME = 'name'; final public const ATTRIBUTE_SEASON = 'season'; final public const ATTRIBUTE_SLUG = 'slug'; final public const ATTRIBUTE_SYNOPSIS = 'synopsis'; final public const ATTRIBUTE_YEAR = 'year'; final public const RELATION_ARTISTS = 'animethemes.song.artists'; final public const RELATION_AUDIO = 'animethemes.animethemeentries.videos.audio'; final public const RELATION_ENTRIES = 'animethemes.animethemeentries'; final public const RELATION_EXTERNAL_ENTRIES = 'externalentries'; final public const RELATION_EXTERNAL_PROFILE = 'externalentries.externalprofile'; final public const RELATION_GROUPS = 'animethemes.group'; final public const RELATION_IMAGES = 'images'; final public const RELATION_RESOURCES = 'resources'; final public const RELATION_SCRIPTS = 'animethemes.animethemeentries.videos.videoscript'; final public const RELATION_SERIES = 'series'; final public const RELATION_SONG = 'animethemes.song'; final public const RELATION_STUDIOS = 'studios'; final public const RELATION_SYNONYMS = 'animesynonyms'; final public const RELATION_THEMES = 'animethemes'; final public const RELATION_VIDEOS = 'animethemes.animethemeentries.videos'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ Anime::ATTRIBUTE_NAME, Anime::ATTRIBUTE_SEASON, Anime::ATTRIBUTE_SLUG, Anime::ATTRIBUTE_SYNOPSIS, Anime::ATTRIBUTE_YEAR, Anime::ATTRIBUTE_MEDIA_FORMAT ]; /** * The event map for the model. * * Allows for object-based events for native Eloquent events. * * @var array */ protected $dispatchesEvents = [ 'created' => AnimeCreated::class, 'deleted' => AnimeDeleted::class, 'deleting' => AnimeDeleting::class, 'restored' => AnimeRestored::class, 'updated' => AnimeUpdated::class, ]; /** * The table associated with the model. * * @var string */ protected $table = Anime::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Anime::ATTRIBUTE_ID; /** * Modify the query used to retrieve models when making all of the models searchable. * * @param Builder $query * @return Builder */ protected function makeAllSearchableUsing(Builder $query): Builder { return $query->with(Anime::RELATION_SYNONYMS); } /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray(): array { $array = $this->toArray(); $array['synonyms'] = $this->animesynonyms->toArray(); return $array; } /** * Get the route key for the model. * * @return string * * @noinspection PhpMissingParentCallCommonInspection */ public function getRouteKeyName(): string { return Anime::ATTRIBUTE_SLUG; } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Anime::ATTRIBUTE_SEASON => AnimeSeason::class, Anime::ATTRIBUTE_YEAR => 'int', Anime::ATTRIBUTE_MEDIA_FORMAT => AnimeMediaFormat::class, ]; } /** * Get name. * * @return string */ public function getName(): string { return $this->name; } /** * Get subtitle. * * @return string */ public function getSubtitle(): string { return $this->slug; } /** * Get the synonyms for the anime. * * @return HasMany */ public function animesynonyms(): HasMany { return $this->hasMany(AnimeSynonym::class, AnimeSynonym::ATTRIBUTE_ANIME); } /** * Get the discord thread that the anime owns. * * @return HasOne */ public function discordthread(): HasOne { return $this->hasOne(DiscordThread::class, DiscordThread::ATTRIBUTE_ANIME); } /** * Get the series the anime is included in. * * @return BelongsToMany */ public function series(): BelongsToMany { return $this->belongsToMany(Series::class, AnimeSeries::TABLE, Anime::ATTRIBUTE_ID, Series::ATTRIBUTE_ID) ->using(AnimeSeries::class) ->as(AnimeSeriesResource::$wrap) ->withTimestamps(); } /** * Get the themes for the anime. * * @return HasMany */ public function animethemes(): HasMany { return $this->hasMany(AnimeTheme::class, AnimeTheme::ATTRIBUTE_ANIME); } /** * Get the resources for the anime. * * @return BelongsToMany */ public function resources(): BelongsToMany { return $this->belongsToMany(ExternalResource::class, AnimeResource::TABLE, Anime::ATTRIBUTE_ID, ExternalResource::ATTRIBUTE_ID) ->using(AnimeResource::class) ->withPivot(AnimeResource::ATTRIBUTE_AS) ->as(AnimeResourceResource::$wrap) ->withTimestamps(); } /** * Get the images for the anime. * * @return BelongsToMany */ public function images(): BelongsToMany { return $this->belongsToMany(Image::class, AnimeImage::TABLE, Anime::ATTRIBUTE_ID, Image::ATTRIBUTE_ID) ->using(AnimeImage::class) ->as(AnimeImageResource::$wrap) ->withTimestamps(); } /** * Get the studios that produced the anime. * * @return BelongsToMany */ public function studios(): BelongsToMany { return $this->belongsToMany(Studio::class, AnimeStudio::TABLE, Anime::ATTRIBUTE_ID, Studio::ATTRIBUTE_ID) ->using(AnimeStudio::class) ->as(AnimeStudioResource::$wrap) ->withTimestamps(); } /** * Get the entries for the anime. * * @return HasMany */ public function externalentries(): HasMany { return $this->hasMany(ExternalEntry::class, ExternalEntry::ATTRIBUTE_ANIME); } }