4baa4cb52b
後端:
- Migration:diving_offers 新增 cover_image 欄位、新增 course_images 表(含索引)
- CourseImage Model(CREATED_AT、url accessor)
- DivingOffer:cover_image_url accessor、hasMany courseImages、static::deleting() 孤兒清理
- CourseImageController:封面上傳/刪除、相簿上傳(max 3)/刪除,統一 mimes+size 驗證
- DivingOfferController:index/show 回傳加入 cover_image_url 與 images 陣列
- 修正 APP_URL 加入 port(:8080),Storage::url() 才能產生正確圖片連結
前端:
- courseImageApi.js:uploadCover/deleteCover/uploadImage/deleteImage
- CourseCard:有封面顯示 <img>,無封面顯示漸層佔位
- CourseDetailView:封面大圖 + 相簿縮圖橫列(點擊開新分頁)
- OfferFormView(編輯模式):封面預覽/更換/刪除、相簿縮圖管理(達 3 張隱藏上傳按鈕)
基礎設施:
- docker-entrypoint.sh:加入 storage:link --force
- docker-compose.yml:移除 storage-data named volume(改用 bind mount,避免 Nginx 讀不到圖片)
測試:
- CourseImageTest.php:14 個 Feature Test 全部 PASS(Storage::fake)
涵蓋:上傳成功/格式驗證/大小驗證/所有權、刪除/無封面不報錯、
相簿上限/sort_order 遞增、孤兒清理
OpenSpec:
- course-images change 歸檔至 archive/2026-05-12-course-images
- 新增 specs/course-image-upload 主規格(含 bind mount 持久化說明)
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
65 lines
1.3 KiB
PHP
65 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class DivingOffer extends Model
|
|
{
|
|
public $timestamps = false;
|
|
|
|
protected $table = 'diving_offers';
|
|
|
|
protected $fillable = [
|
|
'provider_id',
|
|
'title',
|
|
'location',
|
|
'spot',
|
|
'rating',
|
|
'reviews',
|
|
'price',
|
|
'badges',
|
|
'description',
|
|
'tag',
|
|
'region',
|
|
'cover_image',
|
|
];
|
|
|
|
protected $casts = [
|
|
'badges' => 'array',
|
|
'rating' => 'float',
|
|
'price' => 'integer',
|
|
'reviews'=> 'integer',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(function ($offer) {
|
|
Storage::disk('public')->deleteDirectory("offers/{$offer->id}");
|
|
});
|
|
}
|
|
|
|
public function getCoverImageUrlAttribute(): ?string
|
|
{
|
|
return $this->cover_image
|
|
? Storage::disk('public')->url($this->cover_image)
|
|
: null;
|
|
}
|
|
|
|
public function schedules()
|
|
{
|
|
return $this->hasMany(CourseSchedule::class, 'diving_offer_id');
|
|
}
|
|
|
|
public function courseImages()
|
|
{
|
|
return $this->hasMany(CourseImage::class)->orderBy('sort_order');
|
|
}
|
|
|
|
public function reviews()
|
|
{
|
|
return $this->hasMany(Review::class);
|
|
}
|
|
}
|