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

53 lines
1.2 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;
use Livewire\Component;
class InitScript extends Component
{
public array $script;
2024-06-10 20:43:34 +00:00
public int $index;
2024-06-10 20:43:34 +00:00
public ?string $filename;
public ?string $content;
protected $rules = [
'filename' => 'required|string',
'content' => 'required|string',
];
2024-06-10 20:43:34 +00:00
protected $validationAttributes = [
'filename' => 'Filename',
'content' => 'Content',
];
public function mount()
{
$this->index = data_get($this->script, 'index');
$this->filename = data_get($this->script, 'filename');
$this->content = data_get($this->script, 'content');
}
public function submit()
{
$this->validate();
try {
$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()
{
2023-12-07 18:06:32 +00:00
$this->dispatch('delete_init_script', $this->script);
}
}