$anime * @property Collection $artists * @property ImageFacet|null $facet * @property int $image_id * @property string $link * @property string $mimetype * @property string $path * @property Collection $playlists * @property int $size * @property Collection $studios * * @method static ImageFactory factory(...$parameters) */ class Image extends BaseModel implements Auditable, SoftDeletable { use HasAudits; use HasFactory; use SoftDeletes; use Submitable; final public const string TABLE = 'images'; final public const string ATTRIBUTE_FACET = 'facet'; final public const string ATTRIBUTE_ID = 'image_id'; final public const string ATTRIBUTE_PATH = 'path'; final public const string ATTRIBUTE_LINK = 'link'; final public const string RELATION_ANIME = 'anime'; final public const string RELATION_ARTISTS = 'artists'; final public const string RELATION_PLAYLISTS = 'playlists'; final public const string RELATION_STUDIOS = 'studios'; /** * 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; /** * 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, 'forceDeleting' => ImageForceDeleting::class, 'restored' => ImageRestored::class, 'updated' => ImageUpdated::class, ]; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ Image::ATTRIBUTE_FACET, Image::ATTRIBUTE_PATH, ]; /** * The accessors to append to the model's array form. * * @var list */ protected $appends = [ Image::ATTRIBUTE_LINK, ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Image::ATTRIBUTE_FACET => ImageFacet::class, ]; } public function getName(): string { return $this->path; } public function getSubtitle(): string { return $this->path; } protected function getLinkAttribute(): ?string { if ($this->hasAttribute(Image::ATTRIBUTE_PATH) && $this->exists) { /** @var \Illuminate\Filesystem\FilesystemAdapter $fs */ $fs = Storage::disk(Config::get('image.disk')); return $fs->url($this->getAttribute(Image::ATTRIBUTE_PATH)); } return null; } /** * @return MorphToMany */ public function anime(): MorphToMany { return $this->morphedByMany(Anime::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('animeimage') ->withTimestamps(); } /** * @return MorphToMany */ public function artists(): MorphToMany { return $this->morphedByMany(Artist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('artistimage') ->withPivot(Imageable::ATTRIBUTE_DEPTH) ->withTimestamps(); } /** * @return MorphToMany */ public function studios(): MorphToMany { return $this->morphedByMany(Studio::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('studioimage') ->withTimestamps(); } /** * @return MorphToMany */ public function playlists(): MorphToMany { return $this->morphedByMany(Playlist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) ->using(Imageable::class) ->as('playlistimage') ->withTimestamps(); } }