mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-01 00:46:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			76 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Filament\Admin\Resources\DatabaseHosts\RelationManagers;
 | |
| 
 | |
| use App\Filament\Components\Actions\RotateDatabasePasswordAction;
 | |
| use App\Filament\Components\Tables\Columns\DateTimeColumn;
 | |
| use App\Models\Database;
 | |
| use Filament\Actions\DeleteAction;
 | |
| use Filament\Actions\ViewAction;
 | |
| use Filament\Forms\Components\TextInput;
 | |
| use Filament\Resources\RelationManagers\RelationManager;
 | |
| use Filament\Schemas\Schema;
 | |
| use Filament\Tables\Columns\TextColumn;
 | |
| use Filament\Tables\Table;
 | |
| 
 | |
| class DatabasesRelationManager extends RelationManager
 | |
| {
 | |
|     protected static string $relationship = 'databases';
 | |
| 
 | |
|     public function form(Schema $schema): Schema
 | |
|     {
 | |
|         return $schema
 | |
|             ->components([
 | |
|                 TextInput::make('database')
 | |
|                     ->columnSpanFull(),
 | |
|                 TextInput::make('username')
 | |
|                     ->label(trans('admin/databasehost.table.username')),
 | |
|                 TextInput::make('password')
 | |
|                     ->label(trans('admin/databasehost.table.password'))
 | |
|                     ->password()
 | |
|                     ->revealable()
 | |
|                     ->hintAction(RotateDatabasePasswordAction::make())
 | |
|                     ->formatStateUsing(fn (Database $database) => $database->password),
 | |
|                 TextInput::make('remote')
 | |
|                     ->label(trans('admin/databasehost.table.remote'))
 | |
|                     ->formatStateUsing(fn (Database $record) => $record->remote === '%' ? trans('admin/databasehost.anywhere'). ' ( % )' : $record->remote),
 | |
|                 TextInput::make('max_connections')
 | |
|                     ->label(trans('admin/databasehost.table.max_connections'))
 | |
|                     ->formatStateUsing(fn (Database $record) => $record->max_connections === 0 ? trans('admin/databasehost.unlimited') : $record->max_connections),
 | |
|                 TextInput::make('jdbc')
 | |
|                     ->label(trans('admin/databasehost.table.connection_string'))
 | |
|                     ->columnSpanFull()
 | |
|                     ->password()
 | |
|                     ->revealable()
 | |
|                     ->formatStateUsing(fn (Database $database) => $database->jdbc),
 | |
|             ]);
 | |
|     }
 | |
| 
 | |
|     public function table(Table $table): Table
 | |
|     {
 | |
|         return $table
 | |
|             ->recordTitleAttribute('database')
 | |
|             ->heading('')
 | |
|             ->columns([
 | |
|                 TextColumn::make('database'),
 | |
|                 TextColumn::make('username')
 | |
|                     ->label(trans('admin/databasehost.table.username')),
 | |
|                 TextColumn::make('remote')
 | |
|                     ->label(trans('admin/databasehost.table.remote'))
 | |
|                     ->formatStateUsing(fn (Database $record) => $record->remote === '%' ? trans('admin/databasehost.anywhere'). ' ( % )' : $record->remote),
 | |
|                 TextColumn::make('server.name')
 | |
|                     ->url(fn (Database $database) => route('filament.admin.resources.servers.edit', ['record' => $database->server_id])),
 | |
|                 TextColumn::make('max_connections')
 | |
|                     ->label(trans('admin/databasehost.table.max_connections'))
 | |
|                     ->formatStateUsing(fn ($record) => $record->max_connections === 0 ? trans('admin/databasehost.unlimited') : $record->max_connections),
 | |
|                 DateTimeColumn::make('created_at')
 | |
|                     ->label(trans('admin/databasehost.table.created_at')),
 | |
|             ])
 | |
|             ->recordActions([
 | |
|                 ViewAction::make()
 | |
|                     ->color('primary'),
 | |
|                 DeleteAction::make(),
 | |
|             ]);
 | |
|     }
 | |
| }
 | 
