diff --git a/app/Actions/FormattedBranchName.php b/app/Actions/FormattedBranchName.php index 24d09db..c239244 100644 --- a/app/Actions/FormattedBranchName.php +++ b/app/Actions/FormattedBranchName.php @@ -24,7 +24,7 @@ class FormattedBranchName protected const SLUGIFY_DICTIONARY = ['+' => '-', '_' => '-', '@' => '-']; - public function handle(string $branch, ?string $pattern): string + public function handle(string $branch, ?string $pattern = null): string { if (isset($pattern)) { preg_match($pattern, $branch, $matches); diff --git a/app/Services/Forge/ForgeService.php b/app/Services/Forge/ForgeService.php index da2fc7e..c866b17 100644 --- a/app/Services/Forge/ForgeService.php +++ b/app/Services/Forge/ForgeService.php @@ -16,6 +16,7 @@ use App\Actions\FormattedBranchName; use App\Actions\GenerateDomainName; use App\Actions\GenerateStandardizedBranchName; +use Illuminate\Support\Str; use Laravel\Forge\Forge; use Laravel\Forge\Resources\Server; use Laravel\Forge\Resources\Site; @@ -89,9 +90,13 @@ public function getSiteIsolationUsername(): string public function getFormattedDatabaseName(): string { - return $this->setting->dbName ?? GenerateStandardizedBranchName::run( - $this->getFormattedBranchName() - ); + if ($this->setting->dbName) { + $dbName = FormattedBranchName::run($this->setting->dbName); + } else { + $dbName = $this->getFormattedBranchName(); + } + + return Str::replace('-', '_', $dbName); } public function siteNginxTemplate(): string diff --git a/app/Services/Forge/ForgeSetting.php b/app/Services/Forge/ForgeSetting.php index 4f51cf2..0a50417 100644 --- a/app/Services/Forge/ForgeSetting.php +++ b/app/Services/Forge/ForgeSetting.php @@ -206,7 +206,7 @@ class ForgeSetting 'site_isolation_required' => ['boolean'], 'job_scheduler_required' => ['boolean'], 'db_creation_required' => ['boolean'], - 'db_name' => ['nullable', 'string', 'regex:/^[a-zA-Z0-9_]+$/'], + 'db_name' => ['nullable', 'string'], 'auto_source_required' => ['boolean'], 'ssl_required' => ['boolean'], 'wait_on_ssl' => ['boolean'], @@ -230,14 +230,7 @@ public function __construct() private function init(array $configurations): void { - $validator = Validator::make( - $configurations, - $this->validationRules, - [ - 'db_name.regex' => 'The :attribute must only contain letters, numbers, and underscores.' - ], - ['db_name' => 'FORGE_DB_NAME'] - ); + $validator = Validator::make($configurations, $this->validationRules); throw_if($validator->fails(), ValidationException::class, $validator->errors()->all());