2023-05-23 08:15:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project;
|
|
|
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class DeleteEnvironment extends Component
|
|
|
|
{
|
|
|
|
public array $parameters;
|
|
|
|
public int $environment_id;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-06-15 07:15:41 +00:00
|
|
|
$this->parameters = getRouteParameters();
|
2023-05-23 08:15:12 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +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->applications->count() > 0) {
|
|
|
|
return $this->emit('error', 'Environment has resources defined, please delete them first.');
|
|
|
|
}
|
|
|
|
$environment->delete();
|
|
|
|
return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
|
|
|
|
}
|
|
|
|
}
|