Browse Source

update with api

parent
commit
689aa79db1

+ 0
- 10
app/Filament/Resources/BadgeResource.php View File

@@ -59,16 +59,6 @@ class BadgeResource extends Resource
59 59
                             ])->columnSpan(1),
60 60
                         ])->columns(2)->columnSpanFull(),
61 61
                         Group::make()->schema([
62
-                            Select::make("reward_year")->label("認證年份")->options(function () {
63
-                                $currentYear = now()->year;
64
-                                $years = [];
65
-                                for ($i = $currentYear - 20; $i <= $currentYear +5; $i++) {
66
-                                    $years[$i] = strval($i) . '年';
67
-                                }
68
-                                return $years;
69
-                            })->columnSpan(1),
70
-                        ])->columns(2)->columnSpanFull(),
71
-                        Group::make()->schema([
72 62
                             FileUpload::make("img_url")->label("圖片")->directory("badge")->columnSpan(1),
73 63
                         ])->columnSpanFull(),
74 64
                     ])->columns(4)->columnSpanFull(),

+ 128
- 0
app/Filament/Resources/EgsHistoryResource.php View File

@@ -0,0 +1,128 @@
1
+<?php
2
+
3
+namespace App\Filament\Resources;
4
+
5
+use App\Filament\Resources\EgsHistoryResource\Pages;
6
+use App\Filament\Resources\EgsHistoryResource\RelationManagers;
7
+use App\Models\EgsHistory;
8
+use Filament\Forms;
9
+use Filament\Forms\Components\Radio;
10
+use Filament\Forms\Components\Section;
11
+use Filament\Forms\Components\Select;
12
+use Filament\Forms\Components\Textarea;
13
+use Filament\Forms\Components\TextInput;
14
+use Filament\Forms\Form;
15
+use Filament\Resources\Resource;
16
+use Filament\Tables;
17
+use Filament\Tables\Columns\TextColumn;
18
+use Filament\Tables\Filters\SelectFilter;
19
+use Filament\Tables\Table;
20
+use Illuminate\Database\Eloquent\Builder;
21
+use Illuminate\Database\Eloquent\SoftDeletingScope;
22
+use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
23
+use App\Service\DeepLService;
24
+
25
+class EgsHistoryResource extends Resource
26
+{
27
+    protected static ?string $model = EgsHistory::class;
28
+
29
+    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
30
+
31
+    public static function form(Form $form): Form
32
+    {
33
+        return $form
34
+            ->schema([
35
+                Section::make("")->schema([
36
+                    Select::make("selected_year")->label("年份")->options(function () {
37
+                        $currentYear = now()->year;
38
+                        $years = [];
39
+                        // 從 10 年前到 5 年後
40
+                        for ($i = $currentYear - 10; $i <= $currentYear; $i++) {
41
+                            $years[$i] = strval($i) . '年';
42
+                        }
43
+
44
+                        return $years;
45
+                    })->columnSpan(1),
46
+                    Select::make("selected_month")->label("月份")->options(function (){
47
+                        $months = [];
48
+                        for($i=1;$i<=12 ;$i++){
49
+                            $months[$i] = strval($i) . "月";
50
+                        }
51
+                        return $months;
52
+                    })->default(now()->month)->columnSpan(1),
53
+                    Translate::make()->schema(fn (string $locale) => [
54
+                        TextInput::make('title')->required($locale == 'zh_TW')->label("標題"),
55
+                        Textarea::make('description')->required($locale == 'zh_TW')->label("內文"),
56
+                    ])
57
+                    ->locales(["zh_TW", "en"])
58
+                    ->actions([
59
+                        app(DeepLService::class)->createTranslationAction("Main", ["title"])
60
+                    ])->columnSpanFull(),
61
+                    Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)->columnSpan(2)
62
+                ])->columns(3)
63
+            ]);
64
+    }
65
+
66
+    public static function table(Table $table): Table
67
+    {
68
+        return $table
69
+            ->columns([
70
+                TextColumn::make("selected_year")->label("年份")->alignCenter(),
71
+                TextColumn::make("selected_month")->label("月份")->alignCenter(),
72
+                TextColumn::make("title")->label("標題"),
73
+            ])
74
+            ->filters([
75
+                SelectFilter::make('selected_year')->label("年份")
76
+                ->options(function () {
77
+                    $currentYear = now()->year;
78
+                    $years = [];
79
+                    // 從 10 年前到 5 年後
80
+                    for ($i = $currentYear - 10; $i <= $currentYear + 10; $i++) {
81
+                        $years[$i] = strval($i) . '年';
82
+                    }
83
+
84
+                    return $years;
85
+                })
86
+                ->attribute('selected_year'),
87
+                SelectFilter::make('selected_month')->label("月份")
88
+                ->options(function () {
89
+                    $months = [];
90
+                    for($i=1;$i<=12 ;$i++){
91
+                        $months[$i] = strval($i) . "月";
92
+                    }
93
+                    return $months;
94
+                })
95
+                ->attribute('selected_month'),
96
+            ])
97
+            ->actions([
98
+                Tables\Actions\EditAction::make(),
99
+            ])
100
+            ->bulkActions([
101
+                Tables\Actions\BulkActionGroup::make([
102
+                    Tables\Actions\DeleteBulkAction::make(),
103
+                ]),
104
+            ])
105
+            ->modifyQueryUsing(function (Builder $query) {
106
+                // ✅ 正確:多欄位排序
107
+                return $query
108
+                    ->orderBy('selected_year', 'desc')
109
+                    ->orderBy('selected_month', 'desc');
110
+            });
111
+    }
112
+
113
+    public static function getRelations(): array
114
+    {
115
+        return [
116
+            //
117
+        ];
118
+    }
119
+
120
+    public static function getPages(): array
121
+    {
122
+        return [
123
+            'index' => Pages\ListEgsHistories::route('/'),
124
+            'create' => Pages\CreateEgsHistory::route('/create'),
125
+            'edit' => Pages\EditEgsHistory::route('/{record}/edit'),
126
+        ];
127
+    }
128
+}

+ 17
- 0
app/Filament/Resources/EgsHistoryResource/Pages/CreateEgsHistory.php View File

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace App\Filament\Resources\EgsHistoryResource\Pages;
4
+
5
+use App\Filament\Resources\EgsHistoryResource;
6
+use Filament\Actions;
7
+use Filament\Resources\Pages\CreateRecord;
8
+
9
+class CreateEgsHistory extends CreateRecord
10
+{
11
+    protected static string $resource = EgsHistoryResource::class;
12
+
13
+    protected function getRedirectUrl(): string
14
+    {
15
+        return $this->getResource()::getUrl('index');
16
+    }
17
+}

+ 24
- 0
app/Filament/Resources/EgsHistoryResource/Pages/EditEgsHistory.php View File

@@ -0,0 +1,24 @@
1
+<?php
2
+
3
+namespace App\Filament\Resources\EgsHistoryResource\Pages;
4
+
5
+use App\Filament\Resources\EgsHistoryResource;
6
+use Filament\Actions;
7
+use Filament\Resources\Pages\EditRecord;
8
+
9
+class EditEgsHistory extends EditRecord
10
+{
11
+    protected static string $resource = EgsHistoryResource::class;
12
+
13
+    protected function getRedirectUrl(): string
14
+    {
15
+        return $this->getResource()::getUrl('index');
16
+    }
17
+
18
+    protected function getHeaderActions(): array
19
+    {
20
+        return [
21
+            // Actions\DeleteAction::make(),
22
+        ];
23
+    }
24
+}

+ 19
- 0
app/Filament/Resources/EgsHistoryResource/Pages/ListEgsHistories.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Filament\Resources\EgsHistoryResource\Pages;
4
+
5
+use App\Filament\Resources\EgsHistoryResource;
6
+use Filament\Actions;
7
+use Filament\Resources\Pages\ListRecords;
8
+
9
+class ListEgsHistories extends ListRecords
10
+{
11
+    protected static string $resource = EgsHistoryResource::class;
12
+
13
+    protected function getHeaderActions(): array
14
+    {
15
+        return [
16
+            Actions\CreateAction::make()->label("新增"),
17
+        ];
18
+    }
19
+}

+ 1
- 1
app/Filament/Resources/HistoryResource/Pages/EditHistory.php View File

@@ -18,7 +18,7 @@ class EditHistory extends EditRecord
18 18
     protected function getHeaderActions(): array
19 19
     {
20 20
         return [
21
-            Actions\DeleteAction::make(),
21
+            // Actions\DeleteAction::make(),
22 22
         ];
23 23
     }
24 24
 }

+ 43
- 14
app/Filament/Resources/ProjectResource.php View File

@@ -11,6 +11,8 @@ use Filament\Forms;
11 11
 use Filament\Forms\Components\DatePicker;
12 12
 use Filament\Forms\Components\FileUpload;
13 13
 use Filament\Forms\Components\Group;
14
+use Filament\Forms\Components\Hidden;
15
+use Filament\Forms\Components\Radio;
14 16
 use Filament\Forms\Components\Repeater;
15 17
 use Filament\Forms\Components\Section;
16 18
 use Filament\Forms\Components\Select;
@@ -61,6 +63,7 @@ class ProjectResource extends Resource
61 63
                         ->preload()
62 64
                         ->label('標籤'),
63 65
                     FileUpload::make("img_url")->label("圖片")->directory("project")->multiple()->maxFiles(5),
66
+                    TextInput::make('order')->label("排序")->default("0")
64 67
                 ]),
65 68
                 Tabs::make()->schema([
66 69
                     Tab::make("專案概要")->schema([
@@ -79,21 +82,47 @@ class ProjectResource extends Resource
79 82
                             app(DeepLService::class)->createTranslationAction("summaries", ["summaries","address",
80 83
                             "floor_plan","building_structure","design_unit"])
81 84
                         ])->columnSpanFull()->id("summaries"),
82
-                        Select::make('badges')
83
-                            ->multiple()
84
-                            ->relationship('badges', 'title')
85
-                            ->getOptionLabelFromRecordUsing(function ($record) {
86
-                                $imageHtml = $record->img_url
87
-                                    ? '<img src="' . Storage::url($record->img_url) . '" class="w-6 h-6 rounded-full mr-2 inline-block" />'
88
-                                    : '<div class="w-6 h-6 bg-gray-200 rounded-full mr-2 inline-block"></div>';
85
+                        Radio::make("badge_type")->label("標章呈現方式")->options([1 => "永續目標", 2 => "取得標章"])->default(1)->inline(),
86
+                        Repeater::make("badgesTarget")->label("永續目標")->schema([
87
+                            Hidden::make("award_type")->default(1),
88
+                            Select::make('badge_id')
89
+                                ->relationship('badges', 'title')
90
+                                ->getOptionLabelFromRecordUsing(function ($record) {
91
+                                    $imageHtml = $record->img_url
92
+                                        ? '<img src="' . Storage::url($record->img_url) . '" class="w-6 h-6 rounded-full mr-2 inline-block" />'
93
+                                        : '<div class="w-6 h-6 bg-gray-200 rounded-full mr-2 inline-block"></div>';
89 94
 
90
-                                return new \Illuminate\Support\HtmlString($imageHtml . $record->title);
91
-                            })
92
-                            ->allowHtml()
93
-                            ->preload()
94
-                            ->label('取得標章')
95
-                            ->maxItems(8)
96
-                            ->required(),
95
+                                    return new \Illuminate\Support\HtmlString($imageHtml . $record->title);
96
+                                })
97
+                                ->allowHtml()
98
+                                ->preload()
99
+                                ->searchable()
100
+                                ->label('')
101
+                                ->required(),
102
+                        ])->reorderable(false),
103
+                        Repeater::make("badgesAward")->label("取得標章")->schema([
104
+                            Hidden::make("award_type")->default(2),
105
+                            Select::make('badge_id')
106
+                                ->relationship('badges', 'title')
107
+                                ->getOptionLabelFromRecordUsing(function ($record) {
108
+                                    $imageHtml = $record->img_url
109
+                                        ? '<img src="' . Storage::url($record->img_url) . '" class="w-6 h-6 rounded-full mr-2 inline-block" />'
110
+                                        : '<div class="w-6 h-6 bg-gray-200 rounded-full mr-2 inline-block"></div>';
111
+
112
+                                    return new \Illuminate\Support\HtmlString($imageHtml . $record->title);
113
+                                })
114
+                                ->allowHtml()
115
+                                ->preload()
116
+                                ->searchable()
117
+                                ->label('')
118
+                                ->required(),
119
+                            DatePicker::make('award_date')
120
+                                ->label('選擇年月')
121
+                                ->format('Y-m')
122
+                                ->displayFormat('Y年m月')
123
+                                ->native(false)
124
+                                ->closeOnDateSelection()
125
+                        ])->reorderable(false),
97 126
                     ]),
98 127
                     Tab::make("開發歷程")->schema([
99 128
                         Repeater::make("histories")->label("")->schema([

+ 51
- 0
app/Filament/Resources/ProjectResource/Pages/CreateProject.php View File

@@ -3,6 +3,7 @@
3 3
 namespace App\Filament\Resources\ProjectResource\Pages;
4 4
 
5 5
 use App\Filament\Resources\ProjectResource;
6
+use App\Models\Project;
6 7
 use Filament\Actions;
7 8
 use Filament\Resources\Pages\CreateRecord;
8 9
 
@@ -14,4 +15,54 @@ class CreateProject extends CreateRecord
14 15
     {
15 16
         return $this->getResource()::getUrl('index');
16 17
     }
18
+
19
+    protected function mutateFormDataBeforeCreate(array $data): array
20
+    {
21
+        // 暫存標籤資料
22
+        if (isset($data['badgesTarget'])) {
23
+            $this->badgesTargetData = $data['badgesTarget'];
24
+            unset($data['badgesTarget']);
25
+        }
26
+        // 暫存標籤資料
27
+        if (isset($data['badgesAward'])) {
28
+            $this->badgesAwardData = $data['badgesAward'];
29
+            unset($data['badgesAward']);
30
+        }
31
+        return $data;
32
+    }
33
+
34
+    protected function afterCreate(): void
35
+    {
36
+        if (!empty($this->badgesTargetData)) {
37
+            foreach ($this->badgesTargetData as $item) {
38
+                $syncData[$item['badge_id'] . '_1'] = [
39
+                    'badge_id' => $item['badge_id'],
40
+                    'award_type' => 1,
41
+                    'award_date' => null,
42
+                ];
43
+            }
44
+        }
45
+
46
+        if (!empty($this->badgesAwardData)) {
47
+            foreach ($this->badgesAwardData as $item) {
48
+                $syncData[$item['badge_id'] . '_2'] = [
49
+                    'badge_id' => $item['badge_id'],
50
+                    'award_type' => 2,
51
+                    'award_date' => $item['award_date'],
52
+                ];
53
+            }
54
+        }
55
+
56
+        foreach ($syncData as $data) {
57
+            \DB::table('badgeables')->insert([
58
+                'tag_id' => $data['tag_id'],
59
+                'badgeable_id' => $this->record->id,
60
+                'badgeable_type' => Project::class,
61
+                'award_type' => $data['award_type'],
62
+                'award_date' => $data['award_date'],
63
+                'created_at' => now(),
64
+                'updated_at' => now(),
65
+            ]);
66
+        }
67
+    }
17 68
 }

+ 86
- 0
app/Filament/Resources/ProjectResource/Pages/EditProject.php View File

@@ -3,6 +3,7 @@
3 3
 namespace App\Filament\Resources\ProjectResource\Pages;
4 4
 
5 5
 use App\Filament\Resources\ProjectResource;
6
+use App\Models\Project;
6 7
 use Filament\Actions;
7 8
 use Filament\Resources\Pages\EditRecord;
8 9
 
@@ -14,4 +15,89 @@ class EditProject extends EditRecord
14 15
     {
15 16
         return $this->getResource()::getUrl('index');
16 17
     }
18
+
19
+    protected function mutateFormDataBeforeFill(array $data): array
20
+    {
21
+        $project = $this->record;
22
+
23
+        $data['badgesTarget'] = \DB::table('badgeables')
24
+            ->where('badgeable_id', $project->id)
25
+            ->where('badgeable_type', Project::class)
26
+            ->where('award_type', 1)
27
+            ->get()
28
+            ->map(fn ($item) => [
29
+                'badge_id' => $item->badge_id,
30
+                'award_type' => $item->award_type,
31
+            ])->toArray();
32
+
33
+        $data['badgesAwardData'] = \DB::table('badgeables')
34
+        ->where('badgeable_id', $project->id)
35
+        ->where('badgeable_type', Project::class)
36
+        ->where('award_type', 1)
37
+        ->get()
38
+        ->map(fn ($item) => [
39
+            'badge_id' => $item->badge_id,
40
+            'award_date' => $item->award_date,
41
+            'award_type' => $item->award_type,
42
+        ])->toArray();
43
+
44
+        return $data;
45
+    }
46
+
47
+    protected function mutateFormDataBeforeSave(array $data): array
48
+    {
49
+        // 暫存標籤資料
50
+        if (isset($data['badgesTarget'])) {
51
+            $this->badgesTargetData = $data['badgesTarget'];
52
+            unset($data['badgesTarget']);
53
+        }
54
+        // 暫存標籤資料
55
+        if (isset($data['badgesAward'])) {
56
+            $this->badgesAwardData = $data['badgesAward'];
57
+            unset($data['badgesAward']);
58
+        }
59
+        return $data;
60
+    }
61
+
62
+    protected function afterSave(): void
63
+    {
64
+
65
+        // ✅ 先刪除所有舊的標籤
66
+        \DB::table('badgeables')
67
+            ->where('badgeable_id', $this->record->id)
68
+            ->where('badgeable_type', Project::class)
69
+            ->delete();
70
+
71
+        if (!empty($this->badgesTargetData)) {
72
+            foreach ($this->badgesTargetData as $item) {
73
+                $syncData[$item['badge_id'] . '_1'] = [
74
+                    'badge_id' => $item['badge_id'],
75
+                    'award_type' => 1,
76
+                    'award_date' => null,
77
+                ];
78
+            }
79
+        }
80
+
81
+        if (!empty($this->badgesAwardData)) {
82
+            foreach ($this->badgesAwardData as $item) {
83
+                $syncData[$item['badge_id'] . '_2'] = [
84
+                    'badge_id' => $item['badge_id'],
85
+                    'award_type' => 2,
86
+                    'award_date' => $item['award_date'],
87
+                ];
88
+            }
89
+        }
90
+
91
+        foreach ($syncData as $data) {
92
+            \DB::table('badgeables')->insert([
93
+                'tag_id' => $data['tag_id'],
94
+                'badgeable_id' => $this->record->id,
95
+                'badgeable_type' => Project::class,
96
+                'award_type' => $data['award_type'],
97
+                'award_date' => $data['award_date'],
98
+                'created_at' => now(),
99
+                'updated_at' => now(),
100
+            ]);
101
+        }
102
+    }
17 103
 }

+ 12
- 3
app/Http/Controllers/Api/ProjectController.php View File

@@ -95,7 +95,7 @@ class ProjectController extends Controller
95 95
             "floor_plan" => $project->getTranslation("floor_plan", $locale),
96 96
             "building_structure" => $project->getTranslation("building_structure", $locale),
97 97
             "design_unit" => $project->getTranslation("design_unit", $locale),
98
-            "badges" => $project->getBadges($locale),
98
+            "badges" => $project->getBadgesByType($locale, $project->badge_type),
99 99
             "contact_info" => [
100 100
                 "unitName" => $project->getTranslation("contact_unit", $locale),
101 101
                 "unitPhone" => $project->getTranslation("contact_phone", $locale),
@@ -110,14 +110,23 @@ class ProjectController extends Controller
110 110
     public function badges($locale = 'tw') {
111 111
         $locate = $locale == "tw" ? "zh_TW" : $locale;
112 112
 
113
-        $projects = Project::where("visible", 1)->get();
113
+        $projects = Project::where("visible", 1)->where("badge_type", 2)->get();
114 114
         $result = [];
115 115
 
116 116
         foreach($projects as $project){
117
+            $badgesData = $project->awardBadges();
118
+            $badges = [];
119
+            foreach($badgesData as $badge){
120
+                $badges[] = [
121
+                    "imgUrl" => $badge->imgUrlLink,
122
+                    "name" => $badge->getTranslation("name", $locale),
123
+                    "rewardYear" => "取得時間 : " . date("Y.m", strtotime($badge->award_date))
124
+                ];
125
+            }
117 126
             $result[] = [
118 127
                 "id" => $project->id,
119 128
                 "name" => $project->getTranslation("name", $locale),
120
-                "badges" => $project->getBadges($locale)
129
+                "badges" => $badges
121 130
             ];
122 131
         }
123 132
 

+ 16
- 0
app/Models/Badgeable.php View File

@@ -7,4 +7,20 @@ use Illuminate\Database\Eloquent\Model;
7 7
 class Badgeable extends Model
8 8
 {
9 9
     //
10
+    protected $guarded  = ["id"];
11
+    protected $cast = ["award_type" => 'integer'];
12
+
13
+    public function badge()
14
+    {
15
+        return $this->belongsTo(Badge::class);
16
+    }
17
+
18
+    public function getAwardTypeNameAttribute(): string
19
+    {
20
+        return match($this->award_type) {
21
+            1 => '主要標籤',
22
+            2 => '次要標籤',
23
+            default => '未知',
24
+        };
25
+    }
10 26
 }

+ 15
- 0
app/Models/EsgHistoriy.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Casts\Attribute;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Support\Facades\Storage;
8
+use Spatie\Translatable\HasTranslations;
9
+
10
+class EsgHistoriy extends Model
11
+{
12
+    use HasTranslations;
13
+    protected $guarded  = ["id"];
14
+    public $translatable = ['title', 'description'];
15
+}

+ 55
- 1
app/Models/Project.php View File

@@ -32,7 +32,33 @@ class Project extends Model
32 32
 
33 33
     public function badges()
34 34
     {
35
-        return $this->morphToMany(Badge::class, 'badgeable');
35
+        return $this->morphToMany(Badge::class, 'badgeable')
36
+        ->withPivot('award_date')  // ✅ 關鍵
37
+        ->withTimestamps();
38
+    }
39
+
40
+    /**
41
+     * 永續目標
42
+     */
43
+    public function targetBadges()
44
+    {
45
+        return $this->morphToMany(Badge::class, 'badgeable')
46
+            ->using(Badgeable::class)
47
+            ->wherePivot('award_type', 1)
48
+            ->withPivot('award_type')
49
+            ->withTimestamps();
50
+    }
51
+
52
+    /**
53
+     * 取得標章
54
+     */
55
+    public function awardBadges()
56
+    {
57
+        return $this->morphToMany(Badge::class, 'badgeable')
58
+            ->using(Badgeable::class)
59
+            ->wherePivot('award_type', 2)
60
+            ->withPivot('award_type', 'award_date')
61
+            ->withTimestamps();
36 62
     }
37 63
 
38 64
     public function histories()
@@ -88,6 +114,34 @@ class Project extends Model
88 114
         return $badges;
89 115
     }
90 116
 
117
+    public function getBadgesByType($locale, $badgeType) : array
118
+    {
119
+        $badges = [];
120
+        switch($badgeType){
121
+            case "1":
122
+                $badgesData = $this->targetBadges();
123
+                foreach($badgesData as $badge){
124
+                    $badges[] = [
125
+                        "imgUrl" => $badge->imgUrlLink,
126
+                        "name" => null,
127
+                        "rewardYear" => null
128
+                    ];
129
+                }
130
+                break;
131
+            case "2":
132
+                $badgesData = $this->awardBadges();
133
+                foreach($badgesData as $badge){
134
+                    $badges[] = [
135
+                        "imgUrl" => $badge->imgUrlLink,
136
+                        "name" => $badge->getTranslation("name", $locale),
137
+                        "rewardYear" => "取得年份 : " . $badge->award_date
138
+                    ];
139
+                }
140
+                break;
141
+        }
142
+        return $badges;
143
+    }
144
+
91 145
     public function getTags($locale) : array
92 146
     {
93 147
         $tags = [];

+ 0
- 1
database/migrations/2025_09_17_033900_create_badges_table.php View File

@@ -15,7 +15,6 @@ return new class extends Migration
15 15
             $table->id();
16 16
             $table->json("title")->nullable()->comment("標題");
17 17
             $table->string("img_url")->comment("image url");
18
-            $table->string("reward_year")->comment("image 取得年份");
19 18
             $table->integer("order")->default(0);
20 19
             $table->boolean("visible")->default(1);
21 20
             $table->timestamps();

+ 2
- 0
database/migrations/2025_09_18_091406_create_projects_table.php View File

@@ -26,6 +26,8 @@ return new class extends Migration
26 26
             $table->json("contact_unit")->comment("物管單位");
27 27
             $table->json("contact_phone")->comment("物管電話");
28 28
             $table->json("inversment_phone")->comment("招商電話");
29
+            $table->tinyInteger("badge_type")->comment("標章呈現方式");
30
+            $table->integer("order");
29 31
             $table->timestamps();
30 32
             $table->softDeletes();
31 33
         });

+ 3
- 3
database/migrations/2025_09_18_093938_create_badgeables_table.php View File

@@ -14,10 +14,10 @@ return new class extends Migration
14 14
         Schema::create('badgeables', function (Blueprint $table) {
15 15
             $table->id();
16 16
             $table->foreignId('badge_id')->constrained()->cascadeOnDelete();
17
-            $table->morphs('badgeable'); // 創建 taggable_id 和 taggable_type
17
+            $table->morphs('badgeable');
18
+            $table->date("award_date")->comment("取得標章時刻");
19
+            $table->tinyInteger("award_type")->comment("1. 永續目標 2.取得標章");
18 20
             $table->timestamps();
19
-
20
-            $table->unique(['badge_id', 'badgeable_id', 'badgeable_type']);
21 21
         });
22 22
     }
23 23
 

+ 34
- 0
database/migrations/2025_10_30_064958_create_esg_historiys_table.php View File

@@ -0,0 +1,34 @@
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::create('esg_historiys', function (Blueprint $table) {
15
+            $table->id();
16
+            $table->string('selected_year')->comment("年份");
17
+            $table->string('selected_month')->comment("月份");
18
+            $table->dateTime('operate_date')->nullable()->comment("日期 暫時用不到 預留可能以後需要");
19
+            $table->json('title')->comment("標題");
20
+            $table->json('description')->comment("內文");
21
+            $table->boolean('visible')->default(1)->comment("顯示/隱藏");
22
+            $table->timestamps();
23
+            $table->softDeletes();
24
+        });
25
+    }
26
+
27
+    /**
28
+     * Reverse the migrations.
29
+     */
30
+    public function down(): void
31
+    {
32
+        Schema::dropIfExists('esg_historiys');
33
+    }
34
+};