$anime * @property Collection $artists * @property ImageFacet|null $facet * @property int $image_id * @property string $mimetype * @property string $path * @property Collection $playlists * @property int $size * @property Collection $studios * * @method static ImageFactory factory(...$parameters) */ class Image extends BaseModel { final public const TABLE = 'images'; final public const ATTRIBUTE_FACET = 'facet'; final public const ATTRIBUTE_ID = 'image_id'; final public const ATTRIBUTE_PATH = 'path'; final public const RELATION_ANIME = 'anime'; final public const RELATION_ARTISTS = 'artists'; final public const RELATION_PLAYLISTS = 'playlists'; final public const RELATION_STUDIOS = 'studios'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ Image::ATTRIBUTE_FACET, Image::ATTRIBUTE_PATH, ]; /** * The event map for the model. * * Allows for object-based events for native Eloquent events. * * @var array */ protected $dispatchesEvents = [ 'created' => ImageCreated::class, 'deleted' => ImageDeleted::class, 'deleting' => ImageDeleting::class, 'restored' => ImageRestored::class, 'updated' => ImageUpdated::class, ]; /** * The table associated with the model. * * @var string */ protected $table = Image::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Image::ATTRIBUTE_ID; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Image::ATTRIBUTE_FACET => ImageFacet::class, ]; } /** * Get name. * * @return string */ public function getName(): string { return $this->path; } /** * Get subtitle. * * @return string */ public function getSubtitle(): string { return $this->path; } /** * Get the anime that use this image. * * @return BelongsToMany */ public function anime(): BelongsToMany { return $this->belongsToMany(Anime::class, AnimeImage::TABLE, Image::ATTRIBUTE_ID, Anime::ATTRIBUTE_ID) ->using(AnimeImage::class) ->as(AnimeImageResource::$wrap) ->withTimestamps(); } /** * Get the artists that use this image. * * @return BelongsToMany */ public function artists(): BelongsToMany { return $this->belongsToMany(Artist::class, ArtistImage::TABLE, Image::ATTRIBUTE_ID, Artist::ATTRIBUTE_ID) ->using(ArtistImage::class) ->as(ArtistImageResource::$wrap) ->withTimestamps(); } /** * Get the studios that use this image. * * @return BelongsToMany */ public function studios(): BelongsToMany { return $this->belongsToMany(Studio::class, StudioImage::TABLE, Image::ATTRIBUTE_ID, Studio::ATTRIBUTE_ID) ->using(StudioImage::class) ->as(StudioImageResource::$wrap) ->withTimestamps(); } /** * Get the playlists that use this image. * * @return BelongsToMany */ public function playlists(): BelongsToMany { return $this->belongsToMany(Playlist::class, PlaylistImage::TABLE, Image::ATTRIBUTE_ID, Playlist::ATTRIBUTE_ID) ->using(PlaylistImage::class) ->as(PlaylistImageResource::$wrap) ->withTimestamps(); } }