diff --git a/app/Livewire/Server/New/ByHetzner.php b/app/Livewire/Server/New/ByHetzner.php index 788144417..284e5e790 100644 --- a/app/Livewire/Server/New/ByHetzner.php +++ b/app/Livewire/Server/New/ByHetzner.php @@ -69,7 +69,7 @@ class ByHetzner extends Component public ?string $cloud_init_script_name = null; - public ?string $cloud_init_script_description = null; + public ?int $selected_cloud_init_script_id = null; #[Locked] public Collection $saved_cloud_init_scripts; @@ -155,8 +155,8 @@ protected function rules(): array 'enable_ipv6' => 'required|boolean', 'cloud_init_script' => 'nullable|string', 'save_cloud_init_script' => 'boolean', - 'cloud_init_script_name' => 'required_if:save_cloud_init_script,true|nullable|string|max:255', - 'cloud_init_script_description' => 'nullable|string', + 'cloud_init_script_name' => 'nullable|string|max:255', + 'selected_cloud_init_script_id' => 'nullable|integer|exists:cloud_init_scripts,id', ]); } @@ -394,11 +394,12 @@ public function updatedSelectedImage($value) ray('Image selected', $value); } - public function loadCloudInitScript(?int $scriptId) + public function updatedSelectedCloudInitScriptId($value) { - if ($scriptId) { - $script = CloudInitScript::ownedByCurrentTeam()->findOrFail($scriptId); + if ($value) { + $script = CloudInitScript::ownedByCurrentTeam()->findOrFail($value); $this->cloud_init_script = $script->script; + $this->cloud_init_script_name = $script->name; } } @@ -496,14 +497,13 @@ public function submit() } // Save cloud-init script if requested - if ($this->save_cloud_init_script && ! empty($this->cloud_init_script)) { + if ($this->save_cloud_init_script && ! empty($this->cloud_init_script) && ! empty($this->cloud_init_script_name)) { $this->authorize('create', CloudInitScript::class); CloudInitScript::create([ 'team_id' => currentTeam()->id, 'name' => $this->cloud_init_script_name, 'script' => $this->cloud_init_script, - 'description' => $this->cloud_init_script_description, ]); } diff --git a/app/Models/CloudInitScript.php b/app/Models/CloudInitScript.php index 8d2cf72a6..2c78cc582 100644 --- a/app/Models/CloudInitScript.php +++ b/app/Models/CloudInitScript.php @@ -10,7 +10,6 @@ class CloudInitScript extends Model 'team_id', 'name', 'script', - 'description', ]; protected function casts(): array diff --git a/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php b/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php index 15985d986..fe216a57d 100644 --- a/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php +++ b/database/migrations/2025_10_10_120000_create_cloud_init_scripts_table.php @@ -16,7 +16,6 @@ public function up(): void $table->foreignId('team_id')->constrained()->onDelete('cascade'); $table->string('name'); $table->text('script'); // Encrypted in the model - $table->text('description')->nullable(); $table->timestamps(); $table->index('team_id'); diff --git a/resources/views/livewire/server/new/by-hetzner.blade.php b/resources/views/livewire/server/new/by-hetzner.blade.php index a92fcb177..9df8ccea6 100644 --- a/resources/views/livewire/server/new/by-hetzner.blade.php +++ b/resources/views/livewire/server/new/by-hetzner.blade.php @@ -160,9 +160,9 @@ class="p-4 border border-yellow-500 dark:border-yellow-600 rounded bg-yellow-50
@if ($saved_cloud_init_scripts->count() > 0) - - + @foreach ($saved_cloud_init_scripts as $script) @endforeach @@ -173,17 +173,11 @@ class="p-4 border border-yellow-500 dark:border-yellow-600 rounded bg-yellow-50 helper="Add a cloud-init script to run when the server is created. See Hetzner's documentation for details." rows="8" /> -
- - - @if ($save_cloud_init_script) -
- - -
- @endif +
+ +
+ +