mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 11:04:45 +02:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Admin\Resources\DatabaseHostResource\Pages;
|
|
|
|
use App\Filament\Admin\Resources\DatabaseHostResource;
|
|
use App\Services\Databases\Hosts\HostCreationService;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Filament\Support\Exceptions\Halt;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use PDOException;
|
|
|
|
class CreateDatabaseHost extends CreateRecord
|
|
{
|
|
protected static string $resource = DatabaseHostResource::class;
|
|
|
|
protected static bool $canCreateAnother = false;
|
|
|
|
private HostCreationService $service;
|
|
|
|
public function boot(HostCreationService $service): void
|
|
{
|
|
$this->service = $service;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
$this->getCreateFormAction()->formId('form'),
|
|
];
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
protected function handleRecordCreation(array $data): Model
|
|
{
|
|
try {
|
|
return $this->service->handle($data);
|
|
} catch (PDOException $exception) {
|
|
Notification::make()
|
|
->title(trans('admin/databasehost.error'))
|
|
->body($exception->getMessage())
|
|
->color('danger')
|
|
->icon('tabler-database')
|
|
->danger()
|
|
->send();
|
|
|
|
throw new Halt();
|
|
}
|
|
}
|
|
}
|