coolify/app/Livewire/Project/EnvironmentEdit.php

80 lines
2 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Project;
use App\Models\Application;
use App\Models\Project;
use App\Support\ValidationPatterns;
2024-11-03 23:00:58 +00:00
use Livewire\Attributes\Locked;
use Livewire\Component;
class EnvironmentEdit extends Component
{
public Project $project;
2024-06-10 20:43:34 +00:00
public Application $application;
2024-06-10 20:43:34 +00:00
2024-11-03 23:00:58 +00:00
#[Locked]
public $environment;
2024-06-10 20:43:34 +00:00
2024-11-03 23:00:58 +00:00
public string $name;
2024-06-10 20:43:34 +00:00
2024-11-03 23:00:58 +00:00
public ?string $description = null;
2024-06-10 20:43:34 +00:00
protected function rules(): array
{
return [
'name' => ValidationPatterns::nameRules(),
'description' => ValidationPatterns::descriptionRules(),
];
}
protected function messages(): array
{
return ValidationPatterns::combinedMessages();
}
2024-11-22 15:03:20 +00:00
public function mount(string $project_uuid, string $environment_uuid)
2024-01-23 16:13:23 +00:00
{
2024-11-03 23:00:58 +00:00
try {
$this->project = Project::ownedByCurrentTeam()->where('uuid', $project_uuid)->firstOrFail();
2024-11-22 15:03:20 +00:00
$this->environment = $this->project->environments()->where('uuid', $environment_uuid)->firstOrFail();
2024-11-03 23:00:58 +00:00
$this->syncData();
} catch (\Throwable $e) {
2024-11-03 23:00:58 +00:00
return handleError($e, $this);
}
}
public function syncData(bool $toModel = false)
{
if ($toModel) {
$this->validate();
$this->environment->update([
'name' => $this->name,
'description' => $this->description,
]);
} else {
$this->name = $this->environment->name;
$this->description = $this->environment->description;
}
}
public function submit()
{
try {
2024-11-03 23:00:58 +00:00
$this->syncData(true);
2024-11-22 15:03:20 +00:00
$this->redirectRoute('project.environment.edit', [
'environment_uuid' => $this->environment->uuid,
'project_uuid' => $this->project->uuid,
]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
public function render()
{
return view('livewire.project.environment-edit');
}
}