'boolean', 'sort' => 'integer', 'acf_data' => 'array', ]; /** * 註冊媒體集合 */ public function registerMediaCollections(): void { // 成員照片 $this->addMediaCollection('photo') ->singleFile() ->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/webp']) ->registerMediaConversions(function (Media $media) { $this->addMediaConversion('thumb') ->width(200) ->height(200) ->format('webp') ->quality(85) ->nonQueued(); $this->addMediaConversion('medium') ->width(400) ->height(400) ->format('webp') ->quality(85) ->nonQueued(); }); } /** * 從 WordPress ACF 數據導入照片 */ public function importFromWordPress(array $acfFields): void { // 導入照片 (ACF portrait 欄位是 URL) if (!empty($acfFields['portrait'])) { try { // 將相對路徑轉為可訪問的完整路徑 $portraitUrl = $acfFields['portrait']; // 如果是相對路徑,轉為本地路徑 if (strpos($portraitUrl, 'http') === false) { // ../upload/2025/10/... -> public/aia_wp/upload/2025/10/... $localPath = str_replace('../upload/', public_path('aia_wp/upload/'), $portraitUrl); if (file_exists($localPath)) { $this->addMedia($localPath) ->preservingOriginal() ->toMediaCollection('photo'); return; } } // 如果是完整 URL,從 URL 下載 $this->addMediaFromUrl($portraitUrl) ->toMediaCollection('photo'); } catch (\Exception $e) { \Log::warning("Failed to import photo for {$this->name}: " . $e->getMessage()); } } } // Scopes public function scopeActive($query) { return $query->where('is_active', true); } public function scopeBoard($query) { return $query->where('member_type', 'board'); } public function scopeExecutive($query) { return $query->where('member_type', 'executive'); } public function scopeOrdered($query) { return $query->orderBy('display_order')->orderBy('name'); } }