$anime * @property Collection $images * @property string $name * @property string $slug * @property int $studio_id * * @method static StudioFactory factory(...$parameters) */ #[Table(Studio::TABLE, Studio::ATTRIBUTE_ID)] class Studio extends BaseModel implements Auditable, HasImages, HasResources, SoftDeletable { use HasAudits; use HasFactory; use Searchable; use SoftDeletes; use Submitable; final public const string TABLE = 'studios'; final public const string ATTRIBUTE_ID = 'studio_id'; final public const string ATTRIBUTE_NAME = 'name'; final public const string ATTRIBUTE_SLUG = 'slug'; final public const string RELATION_ANIME = 'anime'; final public const string RELATION_IMAGES = 'images'; final public const string RELATION_RESOURCES = 'resources'; /** * The event map for the model. * * Allows for object-based events for native Eloquent events. * * @var array */ protected $dispatchesEvents = [ 'created' => StudioCreated::class, 'deleted' => StudioDeleted::class, 'restored' => StudioRestored::class, 'updated' => StudioUpdated::class, ]; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ Studio::ATTRIBUTE_NAME, Studio::ATTRIBUTE_SLUG, ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Studio::ATTRIBUTE_NAME => 'string', Studio::ATTRIBUTE_SLUG => 'string', ]; } /** * Get the indexable data array for the model. */ public function toSearchableArray(): array { return match ($driver = Config::get('scout.driver')) { 'collection', 'elastic' => StudioElasticModel::toSearchableArray($this), 'typesense' => StudioTypesenseModel::toSearchableArray($this), default => throw new RuntimeException("Unsupported {$driver} search driver configured."), }; } /** * Get the route key for the model. * * @noinspection PhpMissingParentCallCommonInspection */ public function getRouteKeyName(): string { return Studio::ATTRIBUTE_SLUG; } public function getName(): string { return $this->name; } public function getSubtitle(): string { return $this->slug; } /** * @return BelongsToMany */ public function anime(): BelongsToMany { return $this->belongsToMany(Anime::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_STUDIO, AnimeStudio::ATTRIBUTE_ANIME) ->using(AnimeStudio::class) ->as(AnimeStudioJsonResource::$wrap) ->withPivot([AnimeStudio::ATTRIBUTE_ID]) ->withTimestamps(); } /** * @return MorphToMany */ public function resources(): MorphToMany { return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) ->using(Resourceable::class) ->as('studioresource') ->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS]) ->withTimestamps(); } /** * @return MorphToMany */ public function images(): MorphToMany { return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) ->using(Imageable::class) ->as('studioimage') ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH]) ->withTimestamps(); } }