coolify/app/Livewire/Project/Database/InitScript.php

57 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Database;
2023-12-07 18:06:32 +00:00
use Exception;
2024-11-04 11:21:31 +00:00
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
class InitScript extends Component
{
2024-11-04 11:21:31 +00:00
#[Locked]
public array $script;
2024-06-10 20:43:34 +00:00
2024-11-04 11:21:31 +00:00
#[Locked]
public int $index;
2024-06-10 20:43:34 +00:00
#[Validate(['nullable', 'string'])]
2024-11-04 11:21:31 +00:00
public ?string $filename = null;
2024-06-10 20:43:34 +00:00
#[Validate(['nullable', 'string'])]
2024-11-04 11:21:31 +00:00
public ?string $content = null;
public function mount()
{
2024-11-04 11:21:31 +00:00
try {
$this->index = data_get($this->script, 'index');
$this->filename = data_get($this->script, 'filename');
$this->content = data_get($this->script, 'content');
} catch (Exception $e) {
return handleError($e, $this);
}
}
public function submit()
{
try {
2024-11-04 11:21:31 +00:00
$this->validate();
$this->script['index'] = $this->index;
$this->script['content'] = $this->content;
$this->script['filename'] = $this->filename;
2023-12-07 18:06:32 +00:00
$this->dispatch('save_init_script', $this->script);
} catch (Exception $e) {
return handleError($e, $this);
}
}
public function delete()
{
2024-11-04 11:21:31 +00:00
try {
$this->dispatch('delete_init_script', $this->script);
} catch (Exception $e) {
return handleError($e, $this);
}
}
}