2024-05-14 20:10:27 -04:00
|
|
|
<?php
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
namespace App\Filament\Admin\Resources\DatabaseHosts\RelationManagers;
|
2024-05-14 20:10:27 -04:00
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
use App\Filament\Components\Actions\RotateDatabasePasswordAction;
|
2024-12-12 14:14:37 +01:00
|
|
|
use App\Filament\Components\Tables\Columns\DateTimeColumn;
|
2024-05-15 21:21:57 -04:00
|
|
|
use App\Models\Database;
|
2025-09-24 13:34:19 +02:00
|
|
|
use Filament\Actions\DeleteAction;
|
|
|
|
|
use Filament\Actions\ViewAction;
|
2024-06-29 17:38:18 -04:00
|
|
|
use Filament\Forms\Components\TextInput;
|
2024-05-14 20:10:27 -04:00
|
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
2025-09-24 13:34:19 +02:00
|
|
|
use Filament\Schemas\Schema;
|
2024-06-29 17:38:18 -04:00
|
|
|
use Filament\Tables\Columns\TextColumn;
|
2024-05-14 20:10:27 -04:00
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
|
|
|
|
|
class DatabasesRelationManager extends RelationManager
|
|
|
|
|
{
|
|
|
|
|
protected static string $relationship = 'databases';
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
public function form(Schema $schema): Schema
|
2024-05-14 20:10:27 -04:00
|
|
|
{
|
2025-09-08 13:12:33 -04:00
|
|
|
return $schema
|
|
|
|
|
->components([
|
2024-11-30 22:04:10 -05:00
|
|
|
TextInput::make('database')
|
|
|
|
|
->columnSpanFull(),
|
2025-02-08 23:16:54 -05:00
|
|
|
TextInput::make('username')
|
|
|
|
|
->label(trans('admin/databasehost.table.username')),
|
2024-06-29 17:38:18 -04:00
|
|
|
TextInput::make('password')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.password'))
|
2024-11-30 22:04:10 -05:00
|
|
|
->password()
|
|
|
|
|
->revealable()
|
2024-12-12 18:34:52 +01:00
|
|
|
->hintAction(RotateDatabasePasswordAction::make())
|
2024-05-28 15:24:20 +02:00
|
|
|
->formatStateUsing(fn (Database $database) => $database->password),
|
2024-11-30 22:04:10 -05:00
|
|
|
TextInput::make('remote')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.remote'))
|
|
|
|
|
->formatStateUsing(fn (Database $record) => $record->remote === '%' ? trans('admin/databasehost.anywhere'). ' ( % )' : $record->remote),
|
2024-11-30 22:04:10 -05:00
|
|
|
TextInput::make('max_connections')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.max_connections'))
|
2026-01-13 05:33:20 -05:00
|
|
|
->formatStateUsing(fn (Database $record) => $record->max_connections ?: trans('admin/databasehost.unlimited')),
|
2024-12-12 18:34:52 +01:00
|
|
|
TextInput::make('jdbc')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.connection_string'))
|
2024-05-15 21:21:57 -04:00
|
|
|
->columnSpanFull()
|
2024-11-30 22:04:10 -05:00
|
|
|
->password()
|
|
|
|
|
->revealable()
|
2024-12-12 18:34:52 +01:00
|
|
|
->formatStateUsing(fn (Database $database) => $database->jdbc),
|
2024-05-14 20:10:27 -04:00
|
|
|
]);
|
|
|
|
|
}
|
2024-10-19 18:29:44 -04:00
|
|
|
|
2024-05-14 20:10:27 -04:00
|
|
|
public function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
2025-09-08 13:12:33 -04:00
|
|
|
->recordTitleAttribute('database')
|
2025-02-08 23:16:54 -05:00
|
|
|
->heading('')
|
2024-05-14 20:10:27 -04:00
|
|
|
->columns([
|
2025-09-16 11:44:59 -04:00
|
|
|
TextColumn::make('database'),
|
2024-11-30 22:04:10 -05:00
|
|
|
TextColumn::make('username')
|
2025-09-16 11:44:59 -04:00
|
|
|
->label(trans('admin/databasehost.table.username')),
|
2024-11-30 22:04:10 -05:00
|
|
|
TextColumn::make('remote')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.remote'))
|
|
|
|
|
->formatStateUsing(fn (Database $record) => $record->remote === '%' ? trans('admin/databasehost.anywhere'). ' ( % )' : $record->remote),
|
2024-06-29 17:38:18 -04:00
|
|
|
TextColumn::make('server.name')
|
2024-05-17 20:56:12 -04:00
|
|
|
->url(fn (Database $database) => route('filament.admin.resources.servers.edit', ['record' => $database->server_id])),
|
2024-11-30 22:04:10 -05:00
|
|
|
TextColumn::make('max_connections')
|
2025-02-08 23:16:54 -05:00
|
|
|
->label(trans('admin/databasehost.table.max_connections'))
|
2026-01-13 05:33:20 -05:00
|
|
|
->formatStateUsing(fn ($record) => $record->max_connections ?: trans('server/database.unlimited')),
|
2025-02-08 23:16:54 -05:00
|
|
|
DateTimeColumn::make('created_at')
|
|
|
|
|
->label(trans('admin/databasehost.table.created_at')),
|
2024-05-14 20:10:27 -04:00
|
|
|
])
|
2025-09-08 13:12:33 -04:00
|
|
|
->recordActions([
|
2024-11-30 22:04:10 -05:00
|
|
|
ViewAction::make()
|
2025-09-08 13:12:33 -04:00
|
|
|
->color('primary'),
|
2026-01-27 20:07:18 -05:00
|
|
|
DeleteAction::make(),
|
2024-05-14 20:10:27 -04:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|