Andrew před 2 měsíci
rodič
revize
7db939ea66

+ 25
- 25
app/Filament/Resources/EsgHistoryResource.php Zobrazit soubor

47
 
47
 
48
                         return $years;
48
                         return $years;
49
                     })->columnSpan(1),
49
                     })->columnSpan(1),
50
-                    Select::make("selected_month")->label("月份")->options(function (){
50
+                    Select::make("selected_month")->label("月份")->options(function () {
51
                         $months = [];
51
                         $months = [];
52
-                        for($i=1;$i<=12 ;$i++){
52
+                        for ($i = 1; $i <= 12; $i++) {
53
                             $months[$i] = strval($i) . "月";
53
                             $months[$i] = strval($i) . "月";
54
                         }
54
                         }
55
                         return $months;
55
                         return $months;
56
                     })->default(now()->month)->columnSpan(1),
56
                     })->default(now()->month)->columnSpan(1),
57
-                    Translate::make()->schema(fn (string $locale) => [
57
+                    Translate::make()->schema(fn(string $locale) => [
58
                         TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
58
                         TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
59
                         Textarea::make('description')->required($locale == 'zh_TW')->label("內文"),
59
                         Textarea::make('description')->required($locale == 'zh_TW')->label("內文"),
60
                     ])
60
                     ])
61
-                    ->locales(["zh_TW", "en"])
62
-                    ->actions([
63
-                        app(DeepLService::class)->createTranslationAction("Main", ["title", 'description'])
64
-                    ])->columnSpanFull(),
61
+                        ->locales(["zh_TW", "en"])
62
+                        ->actions([
63
+                            app(DeepLService::class)->createTranslationAction("Main", ["title", 'description'])
64
+                        ])->columnSpanFull(),
65
                     Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)->columnSpan(2)
65
                     Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)->columnSpan(2)
66
                 ])->columns(3)
66
                 ])->columns(3)
67
             ]);
67
             ]);
77
             ])
77
             ])
78
             ->filters([
78
             ->filters([
79
                 SelectFilter::make('selected_year')->label("年份")
79
                 SelectFilter::make('selected_year')->label("年份")
80
-                ->options(function () {
81
-                    $currentYear = now()->year;
82
-                    $years = [];
83
-                    // 從 10 年前到 5 年後
84
-                    for ($i = $currentYear - 10; $i <= $currentYear + 10; $i++) {
85
-                        $years[$i] = strval($i) . '年';
86
-                    }
80
+                    ->options(function () {
81
+                        $currentYear = now()->year;
82
+                        $years = [];
83
+                        // 從 10 年前到 5 年後
84
+                        for ($i = $currentYear - 10; $i <= $currentYear + 10; $i++) {
85
+                            $years[$i] = strval($i) . '年';
86
+                        }
87
 
87
 
88
-                    return $years;
89
-                })
90
-                ->attribute('selected_year'),
88
+                        return $years;
89
+                    })
90
+                    ->attribute('selected_year'),
91
                 SelectFilter::make('selected_month')->label("月份")
91
                 SelectFilter::make('selected_month')->label("月份")
92
-                ->options(function () {
93
-                    $months = [];
94
-                    for($i=1;$i<=12 ;$i++){
95
-                        $months[$i] = strval($i) . "月";
96
-                    }
97
-                    return $months;
98
-                })
99
-                ->attribute('selected_month'),
92
+                    ->options(function () {
93
+                        $months = [];
94
+                        for ($i = 1; $i <= 12; $i++) {
95
+                            $months[$i] = strval($i) . "月";
96
+                        }
97
+                        return $months;
98
+                    })
99
+                    ->attribute('selected_month'),
100
             ])
100
             ])
101
             ->actions([
101
             ->actions([
102
                 Tables\Actions\EditAction::make(),
102
                 Tables\Actions\EditAction::make(),

+ 10
- 1
app/Filament/Resources/UploadFileResource.php Zobrazit soubor

4
 
4
 
5
 use App\Filament\Resources\UploadFileResource\Pages;
5
 use App\Filament\Resources\UploadFileResource\Pages;
6
 use App\Models\UploadFile;
6
 use App\Models\UploadFile;
7
+use App\Service\DeepLService;
7
 use Filament\Forms\Components\DatePicker;
8
 use Filament\Forms\Components\DatePicker;
8
 use Filament\Forms\Components\FileUpload;
9
 use Filament\Forms\Components\FileUpload;
9
 use Filament\Forms\Components\Group;
10
 use Filament\Forms\Components\Group;
10
 use Filament\Forms\Components\Radio;
11
 use Filament\Forms\Components\Radio;
11
 use Filament\Forms\Components\Section;
12
 use Filament\Forms\Components\Section;
13
+use Filament\Forms\Components\Textarea;
12
 use Filament\Forms\Components\TextInput;
14
 use Filament\Forms\Components\TextInput;
13
 use Filament\Forms\Form;
15
 use Filament\Forms\Form;
14
 use Filament\Resources\Resource;
16
 use Filament\Resources\Resource;
15
 use Filament\Tables;
17
 use Filament\Tables;
16
 use Filament\Tables\Columns\TextColumn;
18
 use Filament\Tables\Columns\TextColumn;
17
 use Filament\Tables\Table;
19
 use Filament\Tables\Table;
20
+use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
18
 
21
 
19
 class UploadFileResource extends Resource
22
 class UploadFileResource extends Resource
20
 {
23
 {
35
                 //
38
                 //
36
                 Section::make('')->schema([
39
                 Section::make('')->schema([
37
                     Group::make()->schema([
40
                     Group::make()->schema([
38
-                        TextInput::make('title')->required()->label('標題'),
41
+                        Translate::make()->schema(fn(string $locale) => [
42
+                            TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
43
+                        ])
44
+                            ->locales(["zh_TW", "en"])
45
+                            ->actions([
46
+                                app(DeepLService::class)->createTranslationAction("Main", ["title"])
47
+                            ])->columnSpanFull(),
39
                         Radio::make('type')->label('類型')->options([1 => '社會公益'])->default(1),
48
                         Radio::make('type')->label('類型')->options([1 => '社會公益'])->default(1),
40
                         Group::make()->schema([
49
                         Group::make()->schema([
41
                             FileUpload::make('upload_link')->label('上傳檔案')->directory('uploadFiles')->columnSpan(1),
50
                             FileUpload::make('upload_link')->label('上傳檔案')->directory('uploadFiles')->columnSpan(1),