orderBy('order')->orderBy('id'); }); } public static function form(Form $form): Form { return $form ->schema([ // Section::make('')->schema([ Group::make()->schema([ Radio::make('type')->label('')->default(1)->options([1 => '圖片', 2 => '影片'])->reactive(), Translate::make()->schema(fn(string $locale) => [ Textarea::make('title') ->required(fn($get) => $locale == 'zh_TW' && $get('../../type') == 1) ->label('大字標題'), Textarea::make('content') ->required(fn($get) => $locale == 'zh_TW' && $get('../../type') == 1) ->label('小字標題'), ]) ->locales(['zh_TW', 'en']) ->actions([ app(DeepLService::class)->createTranslationAction('Main', ['title', 'content']), ])->columnSpanFull() ->visible(fn($get) => $get('type') == 1), Group::make()->schema([ FileUpload::make('img_url')->label('圖片')->directory('banners')->columnSpan(1) ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp']) ->required(fn($get) => $get('type') == 1) ->imageEditor() ->visible(fn($get) => $get('type') == 1), FileUpload::make('mobile_img')->label('手機板圖片')->directory('banners')->columnSpan(1) ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp']) ->required(fn($get) => $get('type') == 1) ->imageEditor() ->visible(fn($get) => $get('type') == 1), Translate::make()->schema(fn(string $locale) => [ TextInput::make('img_alt') ->required(fn($get) => $locale == 'zh_TW' && $get('../../type') == 1) ->label('圖片註釋'), ]) ->locales(['zh_TW', 'en']) ->actions([ app(DeepLService::class)->createTranslationAction('Main', ['img_alt']), ])->columnSpan(1) ->visible(fn($get) => $get('../type') == 1), ])->columnSpanFull(), TextInput::make('video_url')->label('影片網址')->url()->columnSpanFull() ->required(fn($get) => $get('type') == 2) ->visible(fn($get) => $get('type') == 2), Radio::make('visible')->label('顯示/不顯示')->options([1 => '顯示', 0 => '不顯示'])->inline()->default(1)->columnSpan(2), ])->columns(4)->columnSpanFull(), ]), ]); } public static function table(Table $table): Table { return $table ->columns([ IconColumn::make('type')->label('類別') ->icon(fn (string $state): string => match ($state) { '1' => 'heroicon-o-image', '2' => 'heroicon-o-image', }), ImageColumn::make('img_url')->label('圖片'), TextColumn::make('title')->label('標題'), TextColumn::make('video_url')->label('影片網址'), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->reorderable('order') ->defaultSort('order'); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListBanners::route('/'), 'create' => Pages\CreateBanner::route('/create'), 'edit' => Pages\EditBanner::route('/{record}/edit'), ]; } }