Browse Source

Banner add column mobile image

parent
commit
991881d4a3

+ 3
- 2
app/Filament/Resources/BannerResource.php View File

@@ -49,8 +49,8 @@ class BannerResource extends Resource
49 49
                 Section::make("")->schema([
50 50
                     Group::make()->schema([
51 51
                         Translate::make()->schema(fn (string $locale) => [
52
-                            TextInput::make('title')->required($locale == 'zh_TW')->label("大字標題"),
53
-                            TextInput::make('content')->required($locale == 'zh_TW')->label("小字標題")
52
+                            Textarea::make('title')->required($locale == 'zh_TW')->label("大字標題"),
53
+                            Textarea::make('content')->required($locale == 'zh_TW')->label("小字標題")
54 54
                         ])
55 55
                         ->locales(["zh_TW", "en"])
56 56
                         ->actions([
@@ -58,6 +58,7 @@ class BannerResource extends Resource
58 58
                         ])->columnSpanFull(),
59 59
                         Group::make()->schema([
60 60
                             FileUpload::make("img_url")->label("圖片")->directory("banners")->columnSpan(1),
61
+                            FileUpload::make("mobile_img")->label("手機板圖片")->directory("banners")->columnSpan(1),
61 62
                             Translate::make()->schema(fn (string $locale) => [
62 63
                                 TextInput::make('img_alt')->required($locale == 'zh_TW')->label("圖片註釋")
63 64
                             ])

+ 0
- 7
app/Filament/Resources/HistoryResource.php View File

@@ -66,13 +66,6 @@ class HistoryResource extends Resource
66 66
                     Group::make()->schema([
67 67
                         FileUpload::make("img_url")->label("圖片")->directory("histories")
68 68
                         ->columnSpanFull(),
69
-                        Translate::make()->schema(fn (string $locale) => [
70
-                            TextInput::make('img_alt')->label("圖片註釋"),
71
-                        ])
72
-                        ->locales(["zh_TW", "en"])
73
-                        ->actions([
74
-                            app(DeepLService::class)->createTranslationAction("Image", ["img_alt"])
75
-                        ])->columnSpanFull()
76 69
                     ])->columnSpanFull(),
77 70
                     Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)->columnSpan(2)
78 71
                 ])->columns(3)

+ 14
- 0
app/Http/Controllers/Api/HomePageController.php View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
4 4
 
5 5
 use App\Http\Controllers\Controller;
6 6
 use App\Http\Requests\RegistEPaperRequest;
7
+use App\Models\Banner;
7 8
 use App\Models\EpaperSubscription;
8 9
 use App\Models\HomepageToTop;
9 10
 use App\Models\News;
@@ -23,6 +24,19 @@ class HomePageController extends Controller
23 24
     )
24 25
     {
25 26
     }
27
+    public function banners($locale = 'tw')
28
+    {
29
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
30
+        $result = [];
31
+        $banners = Banner::where("visilbe", true)->get()->map(function ($record) use ($result, $locale){
32
+            $result[] = [
33
+                "imgUrl" => $record->imgUrlLink,
34
+                "mobileImgUrl" => $record->mobileImgLink,
35
+                "title" => $record->getTranslation("title", $locale),
36
+                "content" => $record->getTranslation("content", $locale),
37
+            ];
38
+        });
39
+    }
26 40
 
27 41
     public function list($locale = 'tw')
28 42
     {

+ 8
- 1
app/Models/Banner.php View File

@@ -16,7 +16,7 @@ class Banner extends Model
16 16
     public $translatable = ['title', 'content', 'img_alt'];
17 17
 
18 18
     public $appends = [
19
-        "img_url_link"
19
+        "img_url_link", "mobile_img_link"
20 20
     ];
21 21
 
22 22
     protected function imgUrlLink(): Attribute
@@ -25,4 +25,11 @@ class Banner extends Model
25 25
             get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url),
26 26
         );
27 27
     }
28
+
29
+    protected function mobileImgLink(): Attribute
30
+    {
31
+        return Attribute::make(
32
+            get: fn ($value) => is_null($this->mobile_img) ? null :Storage::url($this->mobile_img),
33
+        );
34
+    }
28 35
 }

+ 29
- 0
database/migrations/2025_11_06_064142_alter_table_banners_add_column_mobile_img.php View File

@@ -0,0 +1,29 @@
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("banners", function (Blueprint $table) {
15
+            $table->string("mobile_img")->comment("手機版圖片");
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        //
25
+        Schema::table("banners", function (Blueprint $table) {
26
+            $table->dropColumn("mobile_img");
27
+        });
28
+    }
29
+};