coolify/app/Livewire/Project/DeleteProject.php

44 lines
1,021 B
PHP
Raw Normal View History

2023-05-09 09:33:50 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project;
2023-05-09 09:33:50 +00:00
use App\Models\Project;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2023-05-09 09:33:50 +00:00
use Livewire\Component;
2023-05-23 08:15:12 +00:00
class DeleteProject extends Component
2023-05-09 09:33:50 +00:00
{
use AuthorizesRequests;
2023-05-23 08:15:12 +00:00
public array $parameters;
2024-06-10 20:43:34 +00:00
2023-05-09 09:33:50 +00:00
public int $project_id;
2024-06-10 20:43:34 +00:00
2024-01-31 13:18:59 +00:00
public bool $disabled = false;
2023-05-09 09:33:50 +00:00
2024-08-30 18:00:04 +00:00
public string $projectName = '';
2023-05-23 08:15:12 +00:00
public function mount()
{
$this->parameters = get_route_parameters();
2024-08-30 18:00:04 +00:00
$this->projectName = Project::findOrFail($this->project_id)->name;
2023-05-23 08:15:12 +00:00
}
2024-09-02 17:27:21 +00:00
public function delete()
2023-05-09 09:33:50 +00:00
{
$this->validate([
'project_id' => 'required|int',
]);
$project = Project::findOrFail($this->project_id);
$this->authorize('delete', $project);
if ($project->isEmpty()) {
$project->delete();
return redirectRoute($this, 'project.index');
2023-05-09 09:33:50 +00:00
}
2024-06-10 20:43:34 +00:00
return $this->dispatch('error', "<strong>Project {$project->name}</strong> has resources defined, please delete them first.");
2023-05-09 09:33:50 +00:00
}
}