schema([ Forms\Components\Section::make('基本資訊') ->schema([ Forms\Components\TextInput::make('title') ->label('標題') ->required() ->maxLength(500) ->columnSpanFull(), Forms\Components\TextInput::make('year') ->label('年份') ->numeric() ->required(), Forms\Components\Select::make('status') ->label('狀態') ->required() ->options([ 'draft' => '草稿', 'publish' => '已發布', ]) ->default('draft'), Forms\Components\DateTimePicker::make('published_at') ->label('發布時間') ->default(now()) ->required(), ]) ->columns(2), Forms\Components\Section::make('內容') ->schema([ Forms\Components\Textarea::make('summary') ->label('簡介') ->rows(4) ->helperText('報告簡介(英文)') ->columnSpanFull(), ]), Forms\Components\Section::make('封面圖') ->schema([ Forms\Components\FileUpload::make('cover_image') ->label('封面圖') ->image() ->disk('uploads') ->directory('reports/covers') ->helperText('上傳報告封面圖') ->columnSpanFull(), ]), Forms\Components\Section::make('下載設定') ->schema([ Forms\Components\Select::make('download_type') ->label('下載類型') ->required() ->options([ 'upload' => '上傳檔案', 'link' => '外部連結', ]) ->default('upload') ->live(), Forms\Components\FileUpload::make('download_file') ->label('下載檔案') ->disk('uploads') ->directory('reports/files') ->helperText('上傳報告檔案(可為任意格式)') ->visible(fn (Forms\Get $get): bool => $get('download_type') === 'upload') ->columnSpanFull(), Forms\Components\TextInput::make('download_url') ->label('外部下載連結') ->url() ->maxLength(500) ->helperText('可填入外部下載連結') ->visible(fn (Forms\Get $get): bool => $get('download_type') === 'link') ->columnSpanFull(), ]) ->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('title') ->label('標題') ->searchable() ->sortable() ->limit(50), Tables\Columns\TextColumn::make('year') ->label('年份') ->sortable(), Tables\Columns\BadgeColumn::make('download_type') ->label('下載類型') ->formatStateUsing(fn (string $state): string => match ($state) { 'upload' => '上傳檔案', 'link' => '外部連結', default => $state, }) ->colors([ 'primary' => 'upload', 'info' => 'link', ]), Tables\Columns\BadgeColumn::make('status') ->label('狀態') ->formatStateUsing(fn (string $state): string => match ($state) { 'draft' => '草稿', 'publish' => '已發布', default => $state, }) ->colors([ 'warning' => 'draft', 'success' => 'publish', ]), Tables\Columns\TextColumn::make('published_at') ->label('發布時間') ->dateTime('Y-m-d H:i') ->sortable(), Tables\Columns\TextColumn::make('created_at') ->label('建立時間') ->dateTime('Y-m-d H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->label('更新時間') ->dateTime('Y-m-d H:i') ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ Tables\Filters\SelectFilter::make('download_type') ->label('下載類型') ->options([ 'upload' => '上傳檔案', 'link' => '外部連結', ]), Tables\Filters\SelectFilter::make('status') ->label('狀態') ->options([ 'draft' => '草稿', 'publish' => '已發布', ]), ]) ->actions([ Tables\Actions\Action::make('download') ->label('下載') ->icon('heroicon-o-arrow-down-tray') ->url(fn (Report $record): ?string => $record->download_type === 'link' ? $record->download_url : route('report.download', $record)) ->openUrlInNewTab() ->visible(fn (Report $record): bool => $record->download_type === 'link' ? !empty($record->download_url) : !empty($record->download_file)), Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->defaultSort('published_at', 'desc'); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListReports::route('/'), 'create' => Pages\CreateReport::route('/create'), 'edit' => Pages\EditReport::route('/{record}/edit'), ]; } }