fix project deletion and refactor some code

This commit is contained in:
peaklabs-dev
2024-10-18 13:48:41 +02:00
parent 5d62a46a16
commit 5a38b21d95
5 changed files with 20 additions and 10 deletions

View File

@@ -27,11 +27,12 @@ class DeleteProject extends Component
'project_id' => 'required|int',
]);
$project = Project::findOrFail($this->project_id);
if ($project->applications->count() > 0) {
return $this->dispatch('error', 'Project has resources defined, please delete them first.');
}
$project->delete();
if ($project->isEmpty()) {
$project->delete();
return redirect()->route('project.index');
return redirect()->route('project.index');
}
return $this->dispatch('error', "<strong>Project {$project->name}</strong> has resources defined, please delete them first.");
}
}