2023-05-09 09:33:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project;
|
|
|
|
|
|
|
|
use App\Models\Project;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
2023-05-23 08:15:12 +00:00
|
|
|
class DeleteProject extends Component
|
2023-05-09 09:33:50 +00:00
|
|
|
{
|
2023-05-23 08:15:12 +00:00
|
|
|
public array $parameters;
|
2023-05-09 09:33:50 +00:00
|
|
|
public int $project_id;
|
|
|
|
|
2023-05-23 08:15:12 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-06-15 07:15:41 +00:00
|
|
|
$this->parameters = getRouteParameters();
|
2023-05-23 08:15:12 +00:00
|
|
|
}
|
2023-05-09 09:33:50 +00:00
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$this->validate([
|
|
|
|
'project_id' => 'required|int',
|
|
|
|
]);
|
|
|
|
$project = Project::findOrFail($this->project_id);
|
|
|
|
if ($project->applications->count() > 0) {
|
2023-05-23 08:15:12 +00:00
|
|
|
return $this->emit('error', 'Project has resources defined, please delete them first.');
|
2023-05-09 09:33:50 +00:00
|
|
|
}
|
|
|
|
$project->delete();
|
2023-05-23 08:15:12 +00:00
|
|
|
return redirect()->route('projects');
|
2023-05-09 09:33:50 +00:00
|
|
|
}
|
|
|
|
}
|