Explorar el Código

project mobile_image_url

Andrew hace 2 meses
padre
commit
e9120cb06c

+ 1
- 0
app/Filament/Resources/ProjectResource.php Ver fichero

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

+ 2
- 0
app/Http/Controllers/Api/ProjectController.php Ver fichero

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

+ 23
- 2
app/Models/Project.php Ver fichero

18
         'building_structure', 'design_unit', 'contact_unit', 'contact_phone', 'inversment_phone', 'district',
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
     public function region()
25
     public function region()
26
     {
26
     {
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
     public function getBadges($locale): array
123
     public function getBadges($locale): array
103
     {
124
     {
104
         $badges = [];
125
         $badges = [];

+ 28
- 0
database/migrations/2025_11_18_102208_add_mobile_img_url_to_projects_table.php Ver fichero

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
+};