|
|
@@ -2,12 +2,10 @@
|
|
2
|
2
|
|
|
3
|
3
|
namespace App\Filament\Resources;
|
|
4
|
4
|
|
|
5
|
|
-use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
|
|
6
|
5
|
use App\Filament\Resources\NewsResource\Pages;
|
|
7
|
|
-use App\Filament\Resources\NewsResource\RelationManagers;
|
|
8
|
6
|
use App\Models\News;
|
|
9
|
7
|
use App\Models\NewsCategory;
|
|
10
|
|
-use Filament\Forms;
|
|
|
8
|
+use App\Service\DeepLService;
|
|
11
|
9
|
use Filament\Forms\Components\DatePicker;
|
|
12
|
10
|
use Filament\Forms\Components\FileUpload;
|
|
13
|
11
|
use Filament\Forms\Components\Group;
|
|
|
@@ -30,115 +28,120 @@ use Filament\Tables\Columns\TextColumn;
|
|
30
|
28
|
use Filament\Tables\Filters\SelectFilter;
|
|
31
|
29
|
use Filament\Tables\Table;
|
|
32
|
30
|
use Illuminate\Database\Eloquent\Builder;
|
|
33
|
|
-use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
34
|
31
|
use Illuminate\Support\Str;
|
|
35
|
32
|
use Malzariey\FilamentLexicalEditor\Enums\ToolbarItem;
|
|
36
|
|
-use Malzariey\FilamentLexicalEditor\FilamentLexicalEditor;
|
|
37
|
33
|
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
|
|
38
|
|
-use App\Service\DeepLService;
|
|
39
|
34
|
|
|
40
|
35
|
class NewsResource extends Resource
|
|
41
|
36
|
{
|
|
42
|
37
|
protected static ?string $model = News::class;
|
|
43
|
38
|
|
|
44
|
39
|
protected static ?string $navigationIcon = 'heroicon-o-newspaper';
|
|
45
|
|
- protected static ?string $navigationLabel = "最新消息管理";
|
|
|
40
|
+
|
|
|
41
|
+ protected static ?string $navigationLabel = '最新消息管理';
|
|
|
42
|
+
|
|
46
|
43
|
protected static ?string $navigationGroup = '最新消息';
|
|
47
|
|
- protected static ?string $modelLabel = "最新消息管理";
|
|
|
44
|
+
|
|
|
45
|
+ protected static ?string $modelLabel = '最新消息管理';
|
|
|
46
|
+
|
|
48
|
47
|
protected static ?int $navigationSort = 3;
|
|
49
|
48
|
|
|
50
|
49
|
public static function form(Form $form): Form
|
|
51
|
50
|
{
|
|
52
|
|
- $editor_toolbar= [
|
|
|
51
|
+ $editor_toolbar = [
|
|
53
|
52
|
ToolbarItem::UNDO, ToolbarItem::REDO, ToolbarItem::NORMAL,
|
|
54
|
53
|
ToolbarItem::H2, ToolbarItem::H3, ToolbarItem::H4, ToolbarItem::H5,
|
|
55
|
54
|
ToolbarItem::BULLET, ToolbarItem::NUMBERED, ToolbarItem::FONT_SIZE,
|
|
56
|
55
|
ToolbarItem::BOLD, ToolbarItem::ITALIC, ToolbarItem::UNDERLINE,
|
|
57
|
56
|
ToolbarItem::LINK, ToolbarItem::TEXT_COLOR, ToolbarItem::BACKGROUND_COLOR,
|
|
58
|
57
|
ToolbarItem::SUBSCRIPT, ToolbarItem::LOWERCASE, ToolbarItem::DIVIDER,
|
|
59
|
|
- ToolbarItem::UPPERCASE, ToolbarItem::CLEAR, ToolbarItem::HR
|
|
|
58
|
+ ToolbarItem::UPPERCASE, ToolbarItem::CLEAR, ToolbarItem::HR,
|
|
60
|
59
|
];
|
|
|
60
|
+
|
|
61
|
61
|
return $form
|
|
62
|
62
|
->schema([
|
|
63
|
63
|
//
|
|
64
|
64
|
Tabs::make()->schema([
|
|
65
|
|
- Tab::make("基本資訊")->schema([
|
|
66
|
|
- Select::make("news_category_id")->label("分類")->options(function (){
|
|
67
|
|
- return NewsCategory::pluck("name", "id");
|
|
|
65
|
+ Tab::make('基本資訊')->schema([
|
|
|
66
|
+ Select::make('news_category_id')->label('分類')->options(function () {
|
|
|
67
|
+ return NewsCategory::pluck('name', 'id');
|
|
68
|
68
|
})->required()
|
|
69
|
|
- ->columnSpan(1),
|
|
70
|
|
- DatePicker::make("post_date")->label("發佈日")
|
|
71
|
|
- ->native(false)
|
|
72
|
|
- ->closeOnDateSelection()
|
|
73
|
|
- ->columnSpan(1),
|
|
74
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
75
|
|
- TextInput::make("title")->required($locale == 'zh_TW')->label("標題")->columnSpan(1),
|
|
76
|
|
- TextInput::make("written_by")->required($locale == 'zh_TW')->label("撰文者")->columnSpan(1),
|
|
77
|
|
- Textarea::make("description")->required($locale == 'zh_TW')->label("簡述")->columnSpan(2)
|
|
|
69
|
+ ->columnSpan(1),
|
|
|
70
|
+ DatePicker::make('post_date')->label('發佈日')
|
|
|
71
|
+ ->native(false)
|
|
|
72
|
+ ->closeOnDateSelection()
|
|
|
73
|
+ ->columnSpan(1),
|
|
|
74
|
+ Translate::make()->schema(fn(string $locale) => [
|
|
|
75
|
+ TextInput::make('title')->required($locale == 'zh_TW')->label('標題')->columnSpan(1),
|
|
|
76
|
+ TextInput::make('written_by')->required($locale == 'zh_TW')->label('撰文者')->columnSpan(1),
|
|
|
77
|
+ Textarea::make('description')->required($locale == 'zh_TW')->label('簡述')->columnSpan(2),
|
|
78
|
78
|
])
|
|
79
|
|
- ->locales(["zh_TW", "en"])
|
|
80
|
|
- ->actions([
|
|
81
|
|
- app(DeepLService::class)->createTranslationAction("Main", ["title", "written_by", "description"])
|
|
82
|
|
- ])->columns(2)
|
|
83
|
|
- ->columnSpan(2)
|
|
84
|
|
- ->id("Main-content"),
|
|
85
|
|
- FileUpload::make("news_img")->label("圖片")
|
|
86
|
|
- ->directory("news")
|
|
87
|
|
- ->columnSpan(2),
|
|
88
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
89
|
|
- TextInput::make('news_img_alt')->label("圖片註釋")
|
|
|
79
|
+ ->locales(['zh_TW', 'en'])
|
|
|
80
|
+ ->actions([
|
|
|
81
|
+ app(DeepLService::class)->createTranslationAction('Main', ['title', 'written_by', 'description']),
|
|
|
82
|
+ ])->columns(2)
|
|
|
83
|
+ ->columnSpan(2)
|
|
|
84
|
+ ->id('Main-content'),
|
|
|
85
|
+ FileUpload::make('news_img')->label('圖片')
|
|
|
86
|
+ ->directory('news')
|
|
|
87
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required()->imageEditor()
|
|
|
88
|
+ ->columnSpan(2),
|
|
|
89
|
+ Translate::make()->schema(fn(string $locale) => [
|
|
|
90
|
+ TextInput::make('news_img_alt')->label('圖片註釋'),
|
|
90
|
91
|
])
|
|
91
|
|
- ->locales(["zh_TW", "en"])
|
|
92
|
|
- ->actions([
|
|
93
|
|
- app(DeepLService::class)->createTranslationAction("NewsImageAlt", ["news_img_alt"])
|
|
94
|
|
- ])->columnSpan(2)
|
|
95
|
|
- ->id("Main-alt"),
|
|
|
92
|
+ ->locales(['zh_TW', 'en'])
|
|
|
93
|
+ ->actions([
|
|
|
94
|
+ app(DeepLService::class)->createTranslationAction('NewsImageAlt', ['news_img_alt']),
|
|
|
95
|
+ ])->columnSpan(2)
|
|
|
96
|
+ ->id('Main-alt'),
|
|
96
|
97
|
])->columns(2),
|
|
97
|
|
- Tab::make("SEO")->schema([
|
|
98
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
99
|
|
- TextInput::make("meta_title")->label("SEO 標題"),
|
|
100
|
|
- TextInput::make("meta_keyword")->label("SEO 關鍵字"),
|
|
101
|
|
- Textarea::make("meta_description")->label("SEO 簡述")
|
|
|
98
|
+ Tab::make('SEO')->schema([
|
|
|
99
|
+ Translate::make()->schema(fn(string $locale) => [
|
|
|
100
|
+ TextInput::make('meta_title')->label('SEO 標題'),
|
|
|
101
|
+ TextInput::make('meta_keyword')->label('SEO 關鍵字'),
|
|
|
102
|
+ Textarea::make('meta_description')->label('SEO 簡述'),
|
|
102
|
103
|
])
|
|
103
|
|
- ->locales(["zh_TW", "en"])
|
|
104
|
|
- ->actions([
|
|
105
|
|
- app(DeepLService::class)->createTranslationAction("Seo", ["meta_title", "meta_keyword", "meta_description"])
|
|
106
|
|
- ])->columnSpanFull(),
|
|
107
|
|
- FileUpload::make('meta_img')->label("放大預覽圖")
|
|
108
|
|
- ->directory("news/seo")
|
|
109
|
|
- ->columnSpan(1)
|
|
110
|
|
- ->id("Seo"),
|
|
|
104
|
+ ->locales(['zh_TW', 'en'])
|
|
|
105
|
+ ->actions([
|
|
|
106
|
+ app(DeepLService::class)->createTranslationAction('Seo', ['meta_title', 'meta_keyword', 'meta_description']),
|
|
|
107
|
+ ])->columnSpanFull(),
|
|
|
108
|
+ FileUpload::make('meta_img')->label('放大預覽圖')
|
|
|
109
|
+ ->directory('news/seo')
|
|
|
110
|
+ ->columnSpan(1)
|
|
|
111
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required()->imageEditor()
|
|
|
112
|
+ ->id('Seo'),
|
|
111
|
113
|
]),
|
|
112
|
|
- Tab::make("內文編輯")->schema([
|
|
113
|
|
- Repeater::make("paragraphs")->schema([
|
|
|
114
|
+ Tab::make('內文編輯')->schema([
|
|
|
115
|
+ Repeater::make('paragraphs')->schema([
|
|
114
|
116
|
TextInput::make('item_key')
|
|
115
|
|
- ->default(fn () => Str::random())
|
|
|
117
|
+ ->default(fn() => Str::random())
|
|
116
|
118
|
->hidden()
|
|
117
|
119
|
->afterStateHydrated(function (TextInput $component, $state) {
|
|
118
|
120
|
if (empty($state)) {
|
|
119
|
121
|
$component->state(Str::random());
|
|
120
|
122
|
}
|
|
121
|
123
|
}),
|
|
122
|
|
- Radio::make("paragraph_type")->options([
|
|
123
|
|
- 1 => "圖片",
|
|
124
|
|
- 2 => "文字",
|
|
|
124
|
+ Radio::make('paragraph_type')->options([
|
|
|
125
|
+ 1 => '圖片',
|
|
|
126
|
+ 2 => '文字',
|
|
125
|
127
|
// 3 => "影音"
|
|
126
|
|
- ])->label("")->inline()->default(1)->Live(),
|
|
|
128
|
+ ])->label('')->inline()->default(1)->Live(),
|
|
127
|
129
|
Group::make()->schema([
|
|
128
|
130
|
Section::make('')->schema([
|
|
129
|
|
- FileUpload::make('img_url')->label("")->directory("news/paragraphs"),
|
|
130
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
131
|
|
- TextInput::make('img_alt')->label("圖片註釋")
|
|
|
131
|
+ FileUpload::make('img_url')->label('')->directory('news/paragraphs')
|
|
|
132
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])->required()->imageEditor(),
|
|
|
133
|
+ Translate::make()->schema(fn(string $locale) => [
|
|
|
134
|
+ TextInput::make('img_alt')->label('圖片註釋'),
|
|
132
|
135
|
])
|
|
133
|
|
- ->locales(["zh_TW", "en"])
|
|
134
|
|
- ->actions([
|
|
135
|
|
- app(DeepLService::class)->createTranslationAction("ParagraphImgAlt", ["img_alt"])
|
|
136
|
|
- ])->columnSpan(1)
|
|
137
|
|
- ->id(fn ($get) => "para_img_" . $get('item_key')),
|
|
138
|
|
- ])
|
|
139
|
|
- ])->visible(fn (Get $get):bool => $get("paragraph_type") == 1),
|
|
|
136
|
+ ->locales(['zh_TW', 'en'])
|
|
|
137
|
+ ->actions([
|
|
|
138
|
+ app(DeepLService::class)->createTranslationAction('ParagraphImgAlt', ['img_alt']),
|
|
|
139
|
+ ])->columnSpan(1)
|
|
|
140
|
+ ->id(fn($get) => 'para_img_' . $get('item_key')),
|
|
|
141
|
+ ]),
|
|
|
142
|
+ ])->visible(fn(Get $get): bool => $get('paragraph_type') == 1),
|
|
140
|
143
|
Group::make()->schema([
|
|
141
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
|
144
|
+ Translate::make()->schema(fn(string $locale) => [
|
|
142
|
145
|
RichEditor::make('text_content')
|
|
143
|
146
|
->toolbarButtons([
|
|
144
|
147
|
'blockquote',
|
|
|
@@ -162,21 +165,21 @@ class NewsResource extends Resource
|
|
162
|
165
|
->fileAttachmentsDisk('s3')
|
|
163
|
166
|
->fileAttachmentsDirectory('attachments')
|
|
164
|
167
|
->fileAttachmentsVisibility('private'),
|
|
165
|
|
- ])
|
|
166
|
|
- ->locales(["zh_TW", "en"])
|
|
167
|
|
- ->actions([
|
|
168
|
|
- app(DeepLService::class)->createTranslationAction("ParagraphText", ["text_content"])
|
|
169
|
|
- ])->columnSpan(1)
|
|
170
|
|
- ->id(fn ($get) => "para_text_" . $get('item_key')),
|
|
171
|
|
- ])->visible(fn (Get $get):bool => $get("paragraph_type") == 2),
|
|
|
168
|
+ ])
|
|
|
169
|
+ ->locales(['zh_TW', 'en'])
|
|
|
170
|
+ ->actions([
|
|
|
171
|
+ app(DeepLService::class)->createTranslationAction('ParagraphText', ['text_content']),
|
|
|
172
|
+ ])->columnSpan(1)
|
|
|
173
|
+ ->id(fn($get) => 'para_text_' . $get('item_key')),
|
|
|
174
|
+ ])->visible(fn(Get $get): bool => $get('paragraph_type') == 2),
|
|
172
|
175
|
])
|
|
173
|
|
- ->relationship("paragraphs")
|
|
174
|
|
- ->label("段落")
|
|
175
|
|
- ->collapsible()
|
|
176
|
|
- ->reorderableWithButtons()
|
|
177
|
|
- ->orderColumn('order')
|
|
178
|
|
- ->cloneable()
|
|
179
|
|
- ])
|
|
|
176
|
+ ->relationship('paragraphs')
|
|
|
177
|
+ ->label('段落')
|
|
|
178
|
+ ->collapsible()
|
|
|
179
|
+ ->reorderableWithButtons()
|
|
|
180
|
+ ->orderColumn('order')
|
|
|
181
|
+ ->cloneable(),
|
|
|
182
|
+ ]),
|
|
180
|
183
|
])->columnSpanFull(),
|
|
181
|
184
|
]);
|
|
182
|
185
|
}
|
|
|
@@ -186,80 +189,78 @@ class NewsResource extends Resource
|
|
186
|
189
|
return $table
|
|
187
|
190
|
->columns([
|
|
188
|
191
|
//
|
|
189
|
|
- TextColumn::make("newsCategory.name")->label("分類")->alignCenter(),
|
|
190
|
|
- TextColumn::make("title")->label("標題")->alignCenter(),
|
|
191
|
|
- TextColumn::make("written_by")->label("發佈者")->alignCenter(),
|
|
192
|
|
- TextColumn::make("post_date")->label("發佈時間")->dateTime('Y/m/d')->alignCenter(),
|
|
193
|
|
- ImageColumn::make("news_img")->label("列表圖")->alignCenter(),
|
|
194
|
|
- TextColumn::make("list_audit_state")->label("狀態")->badge()
|
|
195
|
|
- ->color(fn (string $state): string => match ($state) {
|
|
196
|
|
- '暫存' => 'warning',
|
|
197
|
|
- '已發佈' => 'success',
|
|
198
|
|
- }),
|
|
199
|
|
- IconColumn::make("on_top")->label("置頂")
|
|
200
|
|
- ->color(fn (string $state): string => match ($state) {
|
|
201
|
|
- 1 => 'success',
|
|
202
|
|
- default => ''
|
|
203
|
|
- })
|
|
204
|
|
- ->icon(fn (string $state): string => match ($state) {
|
|
205
|
|
- 1 => 'heroicon-o-check-circle',
|
|
206
|
|
- default => ''
|
|
207
|
|
- })
|
|
208
|
|
- ->action(function ($record): void {
|
|
209
|
|
- $record->on_top = !$record->on_top;
|
|
210
|
|
- $record->save();
|
|
211
|
|
- }),
|
|
212
|
|
- TextColumn::make("created_at")->label("建立時間")->dateTime('Y/m/d H:i:s')->alignCenter(),
|
|
213
|
|
- TextColumn::make("updated_at")->label("更新時間")->dateTime()->alignCenter(),
|
|
|
192
|
+ TextColumn::make('newsCategory.name')->label('分類')->alignCenter(),
|
|
|
193
|
+ TextColumn::make('title')->label('標題')->alignCenter(),
|
|
|
194
|
+ TextColumn::make('written_by')->label('發佈者')->alignCenter(),
|
|
|
195
|
+ TextColumn::make('post_date')->label('發佈時間')->dateTime('Y/m/d')->alignCenter(),
|
|
|
196
|
+ ImageColumn::make('news_img')->label('列表圖')->alignCenter(),
|
|
|
197
|
+ TextColumn::make('list_audit_state')->label('狀態')->badge()
|
|
|
198
|
+ ->color(fn(string $state): string => match ($state) {
|
|
|
199
|
+ '暫存' => 'warning',
|
|
|
200
|
+ '已發佈' => 'success',
|
|
|
201
|
+ }),
|
|
|
202
|
+ IconColumn::make('on_top')->label('置頂')
|
|
|
203
|
+ ->color(fn(string $state): string => match ($state) {
|
|
|
204
|
+ 1 => 'success',
|
|
|
205
|
+ default => ''
|
|
|
206
|
+ })
|
|
|
207
|
+ ->icon(fn(string $state): string => match ($state) {
|
|
|
208
|
+ 1 => 'heroicon-o-check-circle',
|
|
|
209
|
+ default => ''
|
|
|
210
|
+ })
|
|
|
211
|
+ ->action(function ($record): void {
|
|
|
212
|
+ $record->on_top = !$record->on_top;
|
|
|
213
|
+ $record->save();
|
|
|
214
|
+ }),
|
|
|
215
|
+ TextColumn::make('created_at')->label('建立時間')->dateTime('Y/m/d H:i:s')->alignCenter(),
|
|
|
216
|
+ TextColumn::make('updated_at')->label('更新時間')->dateTime()->alignCenter(),
|
|
214
|
217
|
])
|
|
215
|
218
|
->filters([
|
|
216
|
|
- SelectFilter::make('news_category_id')->label("分類")
|
|
217
|
|
- ->options(NewsCategory::orderBy("order")->pluck("name", "id"))
|
|
218
|
|
- ->attribute('news_category_id'),
|
|
219
|
|
- SelectFilter::make('post_date')->label("年份")
|
|
220
|
|
- ->options(News::select(\DB::raw("DATE_FORMAT(post_date, '%Y') as year"))->whereNotNull("post_date")->distinct()->pluck("year","year")->toArray())
|
|
221
|
|
- ->query(
|
|
222
|
|
- fn (array $data, Builder $query): Builder =>
|
|
223
|
|
- $query->when(
|
|
224
|
|
- $data['value'],
|
|
225
|
|
- fn (Builder $query, $value): Builder => $query->where('post_date', 'like', $data['value']. "%")
|
|
226
|
|
- )
|
|
227
|
|
- ),
|
|
228
|
|
- SelectFilter::make('visible')->label("狀態")
|
|
229
|
|
- ->options([
|
|
230
|
|
- 0 => "暫存",
|
|
231
|
|
- 1 => "已發佈",
|
|
232
|
|
- ])
|
|
233
|
|
- ->query(
|
|
234
|
|
- fn (array $data, Builder $query): Builder =>
|
|
235
|
|
- $query->when(
|
|
236
|
|
- $data['value'],
|
|
237
|
|
- fn (Builder $query, $value): Builder => $query->where('visible', $data['value'])
|
|
238
|
|
- )
|
|
239
|
|
- ),
|
|
|
219
|
+ SelectFilter::make('news_category_id')->label('分類')
|
|
|
220
|
+ ->options(NewsCategory::orderBy('order')->pluck('name', 'id'))
|
|
|
221
|
+ ->attribute('news_category_id'),
|
|
|
222
|
+ SelectFilter::make('post_date')->label('年份')
|
|
|
223
|
+ ->options(News::select(\DB::raw("DATE_FORMAT(post_date, '%Y') as year"))->whereNotNull('post_date')->distinct()->pluck('year', 'year')->toArray())
|
|
|
224
|
+ ->query(
|
|
|
225
|
+ fn(array $data, Builder $query): Builder => $query->when(
|
|
|
226
|
+ $data['value'],
|
|
|
227
|
+ fn(Builder $query, $value): Builder => $query->where('post_date', 'like', $data['value'] . '%')
|
|
|
228
|
+ )
|
|
|
229
|
+ ),
|
|
|
230
|
+ SelectFilter::make('visible')->label('狀態')
|
|
|
231
|
+ ->options([
|
|
|
232
|
+ 0 => '暫存',
|
|
|
233
|
+ 1 => '已發佈',
|
|
|
234
|
+ ])
|
|
|
235
|
+ ->query(
|
|
|
236
|
+ fn(array $data, Builder $query): Builder => $query->when(
|
|
|
237
|
+ $data['value'],
|
|
|
238
|
+ fn(Builder $query, $value): Builder => $query->where('visible', $data['value'])
|
|
|
239
|
+ )
|
|
|
240
|
+ ),
|
|
240
|
241
|
])
|
|
241
|
242
|
->actions([
|
|
242
|
243
|
Tables\Actions\EditAction::make(),
|
|
243
|
244
|
Tables\Actions\DeleteAction::make(),
|
|
244
|
|
- \Filament\Tables\Actions\Action::make("audit")
|
|
245
|
|
- ->label(fn ($record) => match ($record->visible) {
|
|
246
|
|
- 0 => '發佈',
|
|
247
|
|
- 1 => '下架',
|
|
248
|
|
- })
|
|
249
|
|
- ->color(fn ($record) => match ($record->visible) {
|
|
250
|
|
- 0 => 'warning',
|
|
251
|
|
- 1 => 'gray',
|
|
252
|
|
- })
|
|
253
|
|
- ->icon(fn ($record) => match ($record->visible) {
|
|
254
|
|
- 0 => 'heroicon-m-chevron-double-up',
|
|
255
|
|
- 1 => 'heroicon-m-chevron-double-down',
|
|
256
|
|
- })
|
|
257
|
|
- ->action(function ($record): void {
|
|
258
|
|
- $record->visible = !$record->visible;
|
|
259
|
|
- $record->save();
|
|
260
|
|
- })
|
|
261
|
|
- ->outlined()
|
|
262
|
|
- ->requiresConfirmation(),
|
|
|
245
|
+ \Filament\Tables\Actions\Action::make('audit')
|
|
|
246
|
+ ->label(fn($record) => match ($record->visible) {
|
|
|
247
|
+ 0 => '發佈',
|
|
|
248
|
+ 1 => '下架',
|
|
|
249
|
+ })
|
|
|
250
|
+ ->color(fn($record) => match ($record->visible) {
|
|
|
251
|
+ 0 => 'warning',
|
|
|
252
|
+ 1 => 'gray',
|
|
|
253
|
+ })
|
|
|
254
|
+ ->icon(fn($record) => match ($record->visible) {
|
|
|
255
|
+ 0 => 'heroicon-m-chevron-double-up',
|
|
|
256
|
+ 1 => 'heroicon-m-chevron-double-down',
|
|
|
257
|
+ })
|
|
|
258
|
+ ->action(function ($record): void {
|
|
|
259
|
+ $record->visible = !$record->visible;
|
|
|
260
|
+ $record->save();
|
|
|
261
|
+ })
|
|
|
262
|
+ ->outlined()
|
|
|
263
|
+ ->requiresConfirmation(),
|
|
263
|
264
|
])
|
|
264
|
265
|
->bulkActions([
|
|
265
|
266
|
Tables\Actions\BulkActionGroup::make([
|