"array"]; protected $appends = ["first_list_img_url", "img_list", "meta_img_url"]; public function region() { return $this->belongsTo(Region::class); } public function tags() { return $this->morphToMany(Tag::class, 'taggable'); } public function badges() { return $this->morphToMany(Badge::class, 'badgeable'); } public function histories() { return $this->hasMany(ProjectHistory::class); } public function spaceInfos() { return $this->hasMany(ProjectSpaceInfo::class); } protected function metaImgUrl(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->meta_img) ? null :Storage::url($this->meta_img), ); } public function firstListImgUrl(): Attribute { return Attribute::make( get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url[0]), ); } public function imgList(): Attribute { $imgList = []; if(!is_null($this->img_url) && count($this->img_url) > 0){ foreach($this->img_url as $img){ $imgList[] = Storage::url($img); } } return Attribute::make( get: fn ($value) => $imgList, ); } public function getBadges($locale) : array { $badges = []; if($this->badges->count() > 0){ foreach($this->badges as $badge){ $badges[] = [ "imgUrl" => $badge->imgUrlLink, "name" => $badge->getTranslation("name", $locale), "rewardYear" => "取得年份 : " . $badge->reward_year ]; } } return $badges; } public function getTags($locale) : array { $tags = []; if($this->tags->count() > 0){ foreach($this->tags as $tag){ $tags[] = [ "id" => $tag->id, "name" => $tag->getTranslation("name", $locale), ]; } } return $tags; } }