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

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

34
     protected static function booted()
34
     protected static function booted()
35
     {
35
     {
36
         static::addGlobalScope('ordered', function ($query) {
36
         static::addGlobalScope('ordered', function ($query) {
37
-            $query->orderBy('order')->orderBy('id');
37
+            $query->orderBy('badges.order')->orderBy('badges.id');
38
         });
38
         });
39
     }
39
     }
40
 
40
 

+ 12
- 7
app/Filament/Resources/ProjectResource.php Просмотреть файл

20
 use Filament\Forms\Components\Textarea;
20
 use Filament\Forms\Components\Textarea;
21
 use Filament\Forms\Components\TextInput;
21
 use Filament\Forms\Components\TextInput;
22
 use Filament\Forms\Form;
22
 use Filament\Forms\Form;
23
-use Filament\Forms\Get;
24
 use Filament\Resources\Resource;
23
 use Filament\Resources\Resource;
25
 use Filament\Tables;
24
 use Filament\Tables;
26
 use Filament\Tables\Columns\ImageColumn;
25
 use Filament\Tables\Columns\ImageColumn;
108
                                 ->searchable()
107
                                 ->searchable()
109
                                 ->label('')
108
                                 ->label('')
110
                                 ->required(),
109
                                 ->required(),
111
-                        ])->reorderable(false),
110
+                        ])
111
+                            ->relationship('targetBadges')
112
+                            ->reorderableWithButtons()
113
+                            ->orderColumn('sort_order'),
112
                         Repeater::make('badgesAward')->label('取得標章')->schema([
114
                         Repeater::make('badgesAward')->label('取得標章')->schema([
113
                             Hidden::make('award_type')->default(2),
115
                             Hidden::make('award_type')->default(2),
114
                             Select::make('badge_id')
116
                             Select::make('badge_id')
133
                                 ->displayFormat('Y年m月')
135
                                 ->displayFormat('Y年m月')
134
                                 ->native(false)
136
                                 ->native(false)
135
                                 ->closeOnDateSelection(),
137
                                 ->closeOnDateSelection(),
136
-                        ])->reorderable(false),
138
+                        ])
139
+                            ->relationship('awardBadges')
140
+                            ->reorderableWithButtons()
141
+                            ->orderColumn('sort_order'),
137
                     ]),
142
                     ]),
138
                     Tab::make('開發歷程')->schema([
143
                     Tab::make('開發歷程')->schema([
139
                         Repeater::make('histories')->label('')->schema([
144
                         Repeater::make('histories')->label('')->schema([
155
                                 ])->columnSpanFull()
160
                                 ])->columnSpanFull()
156
                                 ->id(fn ($get) => 'histories_'.$get('histories_item_key')),
161
                                 ->id(fn ($get) => 'histories_'.$get('histories_item_key')),
157
                         ])
162
                         ])
158
-                            ->relationship('histories', function ($query, Get $get, $livewire) {
159
-                                return $query->orderby('operate_date', 'desc');
160
-                            })
163
+                            ->relationship('histories')
164
+                            ->reorderableWithButtons()
165
+                            ->orderColumn('order')
161
                             ->collapsible()
166
                             ->collapsible()
162
                             ->cloneable(),
167
                             ->cloneable(),
163
                     ]),
168
                     ]),
164
                     Tab::make('空間資訊')->schema([
169
                     Tab::make('空間資訊')->schema([
165
                         Group::make()->schema([
170
                         Group::make()->schema([
166
                             Translate::make()->schema(fn (string $locale) => [
171
                             Translate::make()->schema(fn (string $locale) => [
167
-//                                TextInput::make('contact_unit')->label('物管單位'),
172
+                                //                                TextInput::make('contact_unit')->label('物管單位'),
168
                                 TextInput::make('contact_phone')->label('物管電話'),
173
                                 TextInput::make('contact_phone')->label('物管電話'),
169
                                 TextInput::make('inversment_phone')->label('招商電話'),
174
                                 TextInput::make('inversment_phone')->label('招商電話'),
170
                             ])
175
                             ])

+ 8
- 5
app/Models/Project.php Просмотреть файл

35
     public function badges()
35
     public function badges()
36
     {
36
     {
37
         return $this->morphToMany(Badge::class, 'badgeable')
37
         return $this->morphToMany(Badge::class, 'badgeable')
38
-            ->withPivot('award_date', 'award_type')  // ✅ 關鍵
38
+            ->withPivot('award_date', 'award_type', 'sort_order')
39
+            ->orderByPivot('sort_order')
39
             ->withTimestamps();
40
             ->withTimestamps();
40
     }
41
     }
41
 
42
 
45
     public function targetBadges()
46
     public function targetBadges()
46
     {
47
     {
47
         return $this->morphToMany(Badge::class, 'badgeable')
48
         return $this->morphToMany(Badge::class, 'badgeable')
48
-            ->withPivot('award_type')
49
+            ->withPivot('award_type', 'sort_order')
49
             ->wherePivot('award_type', 1)
50
             ->wherePivot('award_type', 1)
51
+            ->orderByPivot('sort_order')
50
             ->withTimestamps();
52
             ->withTimestamps();
51
     }
53
     }
52
 
54
 
56
     public function awardBadges()
58
     public function awardBadges()
57
     {
59
     {
58
         return $this->morphToMany(Badge::class, 'badgeable')
60
         return $this->morphToMany(Badge::class, 'badgeable')
59
-            ->withPivot('award_type', 'award_date')
61
+            ->withPivot('award_type', 'award_date', 'sort_order')
60
             ->wherePivot('award_type', 2)
62
             ->wherePivot('award_type', 2)
63
+            ->orderByPivot('sort_order')
61
             ->withTimestamps();
64
             ->withTimestamps();
62
     }
65
     }
63
 
66
 
64
     public function histories()
67
     public function histories()
65
     {
68
     {
66
-        return $this->hasMany(ProjectHistory::class);
69
+        return $this->hasMany(ProjectHistory::class)->orderBy('order');
67
     }
70
     }
68
 
71
 
69
     public function spaceInfos()
72
     public function spaceInfos()
70
     {
73
     {
71
-        return $this->hasMany(ProjectSpaceInfo::class);
74
+        return $this->hasMany(ProjectSpaceInfo::class)->orderBy('order');
72
     }
75
     }
73
 
76
 
74
     public function firstListImgUrl(): Attribute
77
     public function firstListImgUrl(): Attribute

+ 28
- 0
database/migrations/2025_12_02_075717_add_order_column_to_badgeables_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('badgeables', function (Blueprint $table) {
15
+            $table->integer('order')->default(0)->after('award_type');
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        Schema::table('badgeables', function (Blueprint $table) {
25
+            $table->dropColumn('order');
26
+        });
27
+    }
28
+};

+ 28
- 0
database/migrations/2025_12_02_075722_add_order_column_to_project_histories_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('project_histories', function (Blueprint $table) {
15
+            $table->integer('order')->default(0)->after('visible');
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        Schema::table('project_histories', function (Blueprint $table) {
25
+            $table->dropColumn('order');
26
+        });
27
+    }
28
+};

+ 28
- 0
database/migrations/2025_12_02_090453_rename_order_to_sort_order_in_badgeables_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('badgeables', function (Blueprint $table) {
15
+            $table->renameColumn('order', 'sort_order');
16
+        });
17
+    }
18
+
19
+    /**
20
+     * Reverse the migrations.
21
+     */
22
+    public function down(): void
23
+    {
24
+        Schema::table('badgeables', function (Blueprint $table) {
25
+            $table->renameColumn('sort_order', 'order');
26
+        });
27
+    }
28
+};