lasthourcloud/app/Livewire/Project/DeleteEnvironment.php

36 lines
831 B
PHP
Raw Normal View History

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 array $parameters;
2024-06-10 20:43:34 +00:00
2023-05-23 08:15:12 +00:00
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
public function mount()
{
$this->parameters = get_route_parameters();
2023-05-23 08:15:12 +00:00
}
2023-05-23 08:15:12 +00:00
public function delete()
{
$this->validate([
'environment_id' => 'required|int',
]);
$environment = Environment::findOrFail($this->environment_id);
if ($environment->isEmpty()) {
$environment->delete();
2024-06-10 20:43:34 +00:00
2023-12-27 15:45:01 +00:00
return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
2023-05-23 08:15:12 +00:00
}
2024-06-10 20:43:34 +00:00
2023-12-07 18:06:32 +00:00
return $this->dispatch('error', 'Environment has defined resources, please delete them first.');
2023-05-23 08:15:12 +00:00
}
}