2023-05-23 08:15:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project;
|
2023-05-23 08:15:12 +00:00
|
|
|
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class DeleteEnvironment extends Component
|
|
|
|
|
{
|
|
|
|
|
public int $environment_id;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-31 13:18:59 +00:00
|
|
|
public bool $disabled = false;
|
2023-05-23 08:15:12 +00:00
|
|
|
|
2024-08-30 18:00:04 +00:00
|
|
|
public string $environmentName = '';
|
|
|
|
|
|
2024-10-17 20:00:27 +00:00
|
|
|
public array $parameters;
|
|
|
|
|
|
2023-05-23 08:15:12 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2024-10-17 20:00:27 +00:00
|
|
|
try {
|
|
|
|
|
$this->environmentName = Environment::findOrFail($this->environment_id)->name;
|
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2023-05-23 08:15:12 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-09-02 17:27:21 +00:00
|
|
|
public function delete()
|
2023-05-23 08:15:12 +00:00
|
|
|
{
|
|
|
|
|
$this->validate([
|
|
|
|
|
'environment_id' => 'required|int',
|
|
|
|
|
]);
|
|
|
|
|
$environment = Environment::findOrFail($this->environment_id);
|
2023-10-24 08:11:21 +00:00
|
|
|
if ($environment->isEmpty()) {
|
|
|
|
|
$environment->delete();
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-10-17 20:00:27 +00:00
|
|
|
return redirect()->route('project.show', parameters: ['project_uuid' => $this->parameters['project_uuid']]);
|
2023-05-23 08:15:12 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-10-18 11:49:17 +00:00
|
|
|
return $this->dispatch('error', "<strong>Environment {$environment->name}</strong> has defined resources, please delete them first.");
|
2023-05-23 08:15:12 +00:00
|
|
|
}
|
|
|
|
|
}
|