$anime * @property Collection $images * @property string $name * @property string $slug * @property int $studio_id * * @method static StudioFactory factory(...$parameters) */ 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 table associated with the model. * * @var string */ protected $table = Studio::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Studio::ATTRIBUTE_ID; /** * 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 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(AnimeStudioResource::$wrap) ->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) ->withPivot(Resourceable::ATTRIBUTE_AS) ->as('studioresource') ->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') ->withTimestamps(); } }