Andrew 2 месяцев назад
Родитель
Сommit
2eb2d974b7

+ 13
- 8
app/Filament/Resources/BannerResource.php Просмотреть файл

49
                 //
49
                 //
50
                 Section::make('')->schema([
50
                 Section::make('')->schema([
51
                     Group::make()->schema([
51
                     Group::make()->schema([
52
-                        Translate::make()->schema(fn(string $locale) => [
52
+                        Translate::make()->schema(fn (string $locale) => [
53
                             Textarea::make('title')->required($locale == 'zh_TW')->label('大字標題'),
53
                             Textarea::make('title')->required($locale == 'zh_TW')->label('大字標題'),
54
                             Textarea::make('content')->required($locale == 'zh_TW')->label('小字標題'),
54
                             Textarea::make('content')->required($locale == 'zh_TW')->label('小字標題'),
55
                         ])
55
                         ])
57
                             ->actions([
57
                             ->actions([
58
                                 app(DeepLService::class)->createTranslationAction('Main', ['title', 'content']),
58
                                 app(DeepLService::class)->createTranslationAction('Main', ['title', 'content']),
59
                             ])->columnSpanFull(),
59
                             ])->columnSpanFull(),
60
-                        Radio::make('type')->label('')->default(1)->options([1 => '圖片', 2 => '影片']),
60
+                        Radio::make('type')->label('')->default(1)->options([1 => '圖片', 2 => '影片'])->reactive(),
61
                         Group::make()->schema([
61
                         Group::make()->schema([
62
                             FileUpload::make('img_url')->label('圖片')->directory('banners')->columnSpan(1)
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
                             FileUpload::make('mobile_img')->label('手機板圖片')->directory('banners')->columnSpan(1)
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
                                 ->locales(['zh_TW', 'en'])
71
                                 ->locales(['zh_TW', 'en'])
70
                                 ->actions([
72
                                 ->actions([
71
                                     app(DeepLService::class)->createTranslationAction('Main', ['img_alt']),
73
                                     app(DeepLService::class)->createTranslationAction('Main', ['img_alt']),
72
-                                ])->columnSpan(1),
74
+                                ])->columnSpan(1)
75
+                                ->visible(fn ($get) => $get('../type') == 1),
73
                         ])->columnSpanFull(),
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
                         Radio::make('visible')->label('顯示/不顯示')->options([1 => '顯示', 0 => '不顯示'])->inline()->default(1)->columnSpan(2),
80
                         Radio::make('visible')->label('顯示/不顯示')->options([1 => '顯示', 0 => '不顯示'])->inline()->default(1)->columnSpan(2),
75
-                        TextInput::make('order')->label('排序')->default('0'),
76
                     ])->columns(4)->columnSpanFull(),
81
                     ])->columns(4)->columnSpanFull(),
77
                 ]),
82
                 ]),
78
             ]);
83
             ]);

+ 1
- 0
app/Http/Controllers/Api/HomePageController.php Просмотреть файл

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

+ 28
- 0
database/migrations/2025_12_02_072441_add_video_url_to_banners_table.php Просмотреть файл

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