Browse Source

project mobile_image_url

Andrew 1 day ago
parent
commit
e9120cb06c

+ 1
- 0
app/Filament/Resources/ProjectResource.php View File

@@ -66,6 +66,7 @@ class ProjectResource extends Resource
66 66
                         ->label('標籤'),
67 67
                     FileUpload::make('thumbnail')->label('縮圖')->directory('project')->image(),
68 68
                     FileUpload::make('img_url')->label('圖片')->directory('project')->multiple()->maxFiles(5),
69
+                    FileUpload::make('mobile_img_url')->label('手機版圖片')->directory('project')->multiple()->maxFiles(5),
69 70
                     TextInput::make('order')->label('排序')->default('0'),
70 71
                 ]),
71 72
                 Tabs::make()->schema([

+ 2
- 0
app/Http/Controllers/Api/ProjectController.php View File

@@ -69,6 +69,7 @@ class ProjectController extends Controller
69 69
                 'name' => $project->getTranslation('name', $locale),
70 70
                 'thumbnail' => $project->thumbnail_url,
71 71
                 'imgUrl' => $project->first_list_img_url,
72
+                'mobileImgUrl' => $project->first_mobile_img_url,
72 73
             ];
73 74
         }
74 75
 
@@ -103,6 +104,7 @@ class ProjectController extends Controller
103 104
             'description' => $project->getTranslation('summaries', $locale),
104 105
             'thumbnail' => $project->thumbnail_url,
105 106
             'images' => $project->img_list,
107
+            'mobileImages' => $project->mobile_img_list,
106 108
             'region_id' => $project->region_id,
107 109
             'region' => $project->region->getTranslation('name', $locale),
108 110
             'address' => $project->getTranslation('address', $locale),

+ 23
- 2
app/Models/Project.php View File

@@ -18,9 +18,9 @@ class Project extends Model
18 18
         'building_structure', 'design_unit', 'contact_unit', 'contact_phone', 'inversment_phone', 'district',
19 19
     ];
20 20
 
21
-    protected $casts = ['img_url' => 'array'];
21
+    protected $casts = ['img_url' => 'array', 'mobile_img_url' => 'array'];
22 22
 
23
-    protected $appends = ['first_list_img_url', 'img_list', 'thumbnail_url'];
23
+    protected $appends = ['first_list_img_url', 'img_list', 'thumbnail_url', 'first_mobile_img_url', 'mobile_img_list'];
24 24
 
25 25
     public function region()
26 26
     {
@@ -99,6 +99,27 @@ class Project extends Model
99 99
         );
100 100
     }
101 101
 
102
+    public function firstMobileImgUrl(): Attribute
103
+    {
104
+        return Attribute::make(
105
+            get: fn ($value) => ! empty($this->mobile_img_url) ? Storage::url($this->mobile_img_url[0]) : null,
106
+        );
107
+    }
108
+
109
+    public function mobileImgList(): Attribute
110
+    {
111
+        $imgList = [];
112
+        if (! is_null($this->mobile_img_url) && count($this->mobile_img_url) > 0) {
113
+            foreach ($this->mobile_img_url as $img) {
114
+                $imgList[] = Storage::url($img);
115
+            }
116
+        }
117
+
118
+        return Attribute::make(
119
+            get: fn ($value) => $imgList,
120
+        );
121
+    }
122
+
102 123
     public function getBadges($locale): array
103 124
     {
104 125
         $badges = [];

+ 28
- 0
database/migrations/2025_11_18_102208_add_mobile_img_url_to_projects_table.php View File

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     */
12
+    public function up(): void
13
+    {
14
+        Schema::table('projects', function (Blueprint $table) {
15
+            $table->json('mobile_img_url')->nullable()->after('img_url');
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        Schema::table('projects', function (Blueprint $table) {
25
+            $table->dropColumn('mobile_img_url');
26
+        });
27
+    }
28
+};