Andrew преди 2 месеца
родител
ревизия
2eb2d974b7

+ 13
- 8
app/Filament/Resources/BannerResource.php Целия файл

@@ -49,7 +49,7 @@ class BannerResource extends Resource
49 49
                 //
50 50
                 Section::make('')->schema([
51 51
                     Group::make()->schema([
52
-                        Translate::make()->schema(fn(string $locale) => [
52
+                        Translate::make()->schema(fn (string $locale) => [
53 53
                             Textarea::make('title')->required($locale == 'zh_TW')->label('大字標題'),
54 54
                             Textarea::make('content')->required($locale == 'zh_TW')->label('小字標題'),
55 55
                         ])
@@ -57,22 +57,27 @@ class BannerResource extends Resource
57 57
                             ->actions([
58 58
                                 app(DeepLService::class)->createTranslationAction('Main', ['title', 'content']),
59 59
                             ])->columnSpanFull(),
60
-                        Radio::make('type')->label('')->default(1)->options([1 => '圖片', 2 => '影片']),
60
+                        Radio::make('type')->label('')->default(1)->options([1 => '圖片', 2 => '影片'])->reactive(),
61 61
                         Group::make()->schema([
62 62
                             FileUpload::make('img_url')->label('圖片')->directory('banners')->columnSpan(1)
63
-                                ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required()->imageEditor(),
63
+                                ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required(fn ($get) => $get('type') == 1)->imageEditor()
64
+                                ->visible(fn ($get) => $get('type') == 1),
64 65
                             FileUpload::make('mobile_img')->label('手機板圖片')->directory('banners')->columnSpan(1)
65
-                                ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required()->imageEditor(),
66
-                            Translate::make()->schema(fn(string $locale) => [
67
-                                TextInput::make('img_alt')->required($locale == 'zh_TW')->label('圖片註釋'),
66
+                                ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required(fn ($get) => $get('type') == 1)->imageEditor()
67
+                                ->visible(fn ($get) => $get('type') == 1),
68
+                            Translate::make()->schema(fn (string $locale) => [
69
+                                TextInput::make('img_alt')->required(fn ($get) => $locale == 'zh_TW' && $get('../../type') == 1)->label('圖片註釋'),
68 70
                             ])
69 71
                                 ->locales(['zh_TW', 'en'])
70 72
                                 ->actions([
71 73
                                     app(DeepLService::class)->createTranslationAction('Main', ['img_alt']),
72
-                                ])->columnSpan(1),
74
+                                ])->columnSpan(1)
75
+                                ->visible(fn ($get) => $get('../type') == 1),
73 76
                         ])->columnSpanFull(),
77
+                        TextInput::make('video_url')->label('影片網址')->url()->columnSpanFull()
78
+                            ->required(fn ($get) => $get('type') == 2)
79
+                            ->visible(fn ($get) => $get('type') == 2),
74 80
                         Radio::make('visible')->label('顯示/不顯示')->options([1 => '顯示', 0 => '不顯示'])->inline()->default(1)->columnSpan(2),
75
-                        TextInput::make('order')->label('排序')->default('0'),
76 81
                     ])->columns(4)->columnSpanFull(),
77 82
                 ]),
78 83
             ]);

+ 1
- 0
app/Http/Controllers/Api/HomePageController.php Целия файл

@@ -32,6 +32,7 @@ class HomePageController extends Controller
32 32
             $result[] = [
33 33
                 "imgUrl" => $record->imgUrlLink,
34 34
                 "mobileImgUrl" => $record->mobileImgLink,
35
+                "videoUrl" => $record->video_url,
35 36
                 "type" => $record->type,
36 37
                 "title" => $record->getTranslation("title", $locale),
37 38
                 "content" => $record->getTranslation("content", $locale),

+ 28
- 0
database/migrations/2025_12_02_072441_add_video_url_to_banners_table.php Целия файл

@@ -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('banners', function (Blueprint $table) {
15
+            $table->text('video_url')->nullable()->after('mobile_img');
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        Schema::table('banners', function (Blueprint $table) {
25
+            $table->dropColumn('video_url');
26
+        });
27
+    }
28
+};