'boolean', "list_audit_state" => "string" ]; protected $guarded = ['id']; protected $appends = ["album_img_pc_url", "album_img_pc_url", "album_img_banner_url", "album_img_mobile_url", "album_meta_img", "album_upload_type", "album_video_link"]; public $translatable = ['title', 'description', 'meta_title', 'meta_description', 'meta_keyword']; public function albumCategory(){ return $this->belongsTo(AlbumCategory::class); } protected function albumImgPcUrl(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->news_img_pc) ? null :Storage::disk('s3')->url($this->news_img_pc), ); } protected function albumImgMobileUrl(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->news_img_mobile) ? null :Storage::disk('s3')->url($this->news_img_mobile), ); } protected function albumMetaImg(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->meta_img) ? null :Storage::disk('s3')->url($this->meta_img), ); } protected function albumImgBannerUrl(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->news_banner) ? null :Storage::disk('s3')->url($this->news_banner), ); } protected function albumUploadType(): Attribute { return Attribute::make( get: fn ($value) => $this->attributes["upload_type"] == 1 ? "url" : "upload", ); } protected function listAuditState(): Attribute { return Attribute::make( get: fn ($value) => $this->attributes["visible"] == 1 ? "已發佈" : "暫存", ); } protected function albumVideoLink(): Attribute { return Attribute::make( get: fn ($value) => ($this->attributes["upload_type"] == 2) ? Storage::disk('s3')->url($this->attributes["link"]) : $this->attributes["link"], ); } public function homepageToTop() { return $this->morphOne(HomepageToTop::class, 'resource'); } protected static function booted() { static::created(function ($album) { if ($album->homepage_top) { $album->createOrUpdatePageSet(); } }); static::updated(function ($album) { if ($album->isDirty('homepage_top')) { if ($album->homepage_top) { $album->createOrUpdatePageSet(); } else { $album->homepageToTop()->delete(); } } }); static::deleted(function ($album) { $album->homepageToTop()->delete(); }); } protected function createOrUpdatePageSet() { $this->homepageToTop()->updateOrCreate( [], ['resource' => 'video'] ); } }