coolify/app/Livewire/Project/Show.php

62 lines
1.5 KiB
PHP
Raw Normal View History

2024-01-07 15:23:41 +00:00
<?php
namespace App\Livewire\Project;
use App\Models\Environment;
2024-01-07 15:23:41 +00:00
use App\Models\Project;
use Livewire\Attributes\Validate;
2024-01-07 15:23:41 +00:00
use Livewire\Component;
2024-11-22 14:38:54 +00:00
use Visus\Cuid2\Cuid2;
2024-01-07 15:23:41 +00:00
class Show extends Component
{
public Project $project;
2024-06-10 20:43:34 +00:00
#[Validate(['required', 'string', 'min:3'])]
public string $name;
#[Validate(['nullable', 'string'])]
public ?string $description = null;
2024-01-07 15:23:41 +00:00
public function mount(string $project_uuid)
{
try {
$this->project = Project::where('team_id', currentTeam()->id)->where('uuid', $project_uuid)->firstOrFail();
} catch (\Throwable $e) {
return handleError($e, $this);
2024-01-07 15:23:41 +00:00
}
}
public function submit()
{
try {
$this->validate();
$environment = Environment::create([
'name' => $this->name,
'project_id' => $this->project->id,
2024-11-22 14:38:54 +00:00
'uuid' => (string) new Cuid2,
]);
return redirect()->route('project.resource.index', [
'project_uuid' => $this->project->uuid,
2024-11-22 14:38:54 +00:00
'environment_uuid' => $environment->uuid,
]);
} catch (\Throwable $e) {
handleError($e, $this);
}
2024-01-07 15:23:41 +00:00
}
2024-06-10 20:43:34 +00:00
2024-11-22 14:38:54 +00:00
public function navigateToEnvironment($projectUuid, $environmentUuid)
{
return redirect()->route('project.resource.index', [
'project_uuid' => $projectUuid,
'environment_uuid' => $environmentUuid,
]);
}
2024-01-07 15:23:41 +00:00
public function render()
{
return view('livewire.project.show');
}
}