lasthourcloud/app/Http/Livewire/Project/Service/Application.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2023-09-22 09:23:49 +00:00
<?php
namespace App\Http\Livewire\Project\Service;
use App\Models\ServiceApplication;
use Livewire\Component;
class Application extends Component
{
public ServiceApplication $application;
2023-09-25 13:48:43 +00:00
public $parameters;
public $fileStorages = null;
protected $listeners = ["refreshFileStorages"];
2023-09-22 09:23:49 +00:00
protected $rules = [
'application.human_name' => 'nullable',
'application.description' => 'nullable',
2023-09-22 09:23:49 +00:00
'application.fqdn' => 'nullable',
2023-09-25 15:51:04 +00:00
'application.image_tag' => 'required',
2023-09-25 13:48:43 +00:00
'application.ignore_from_status' => 'required|boolean',
2023-09-22 09:23:49 +00:00
];
public function render()
{
return view('livewire.project.service.application');
}
2023-09-25 13:48:43 +00:00
public function instantSave() {
$this->submit();
}
public function refreshFileStorages()
{
$this->fileStorages = $this->application->fileStorages()->get();
}
2023-09-25 13:48:43 +00:00
public function delete()
{
try {
$this->application->delete();
$this->emit('success', 'Application deleted successfully.');
return redirect()->route('project.service', $this->parameters);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
2023-09-25 13:48:43 +00:00
$this->parameters = get_route_parameters();
$this->refreshFileStorages();
}
2023-09-22 09:23:49 +00:00
public function submit()
{
try {
$this->validate();
$this->application->save();
$this->emit('success', 'Application saved successfully.');
2023-09-22 09:23:49 +00:00
} catch (\Throwable $e) {
ray($e);
} finally {
$this->emit('generateDockerCompose');
}
}
}