coolify/app/Livewire/Project/EnvironmentEdit.php

64 lines
2.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Project;
use App\Models\Application;
use App\Models\Project;
use Livewire\Component;
class EnvironmentEdit extends Component
{
public Project $project;
public Application $application;
public $environment;
public array $parameters;
protected $rules = [
'environment.name' => 'required|min:3|max:255',
'environment.description' => 'nullable|min:3|max:255',
];
2024-01-23 17:13:23 +01:00
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];
2024-01-23 17:13:23 +01:00
public function saveKey($data)
{
try {
2024-03-15 22:02:37 +01:00
$found = $this->environment->environment_variables()->where('key', $data['key'])->first();
if ($found) {
throw new \Exception('Variable already exists.');
}
2024-01-23 17:13:23 +01:00
$this->environment->environment_variables()->create([
'key' => $data['key'],
'value' => $data['value'],
2024-03-15 22:02:37 +01:00
'is_multiline' => $data['is_multiline'],
2024-04-15 12:46:22 +02:00
'is_literal' => $data['is_literal'],
2024-01-23 17:13:23 +01:00
'type' => 'environment',
'team_id' => currentTeam()->id,
]);
$this->environment->refresh();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
$this->parameters = get_route_parameters();
$this->project = Project::ownedByCurrentTeam()->where('uuid', request()->route('project_uuid'))->first();
$this->environment = $this->project->environments()->where('name', request()->route('environment_name'))->first();
}
public function submit()
{
$this->validate();
try {
$this->environment->save();
return redirect()->route('project.environment.edit', ['project_uuid' => $this->project->uuid, 'environment_name' => $this->environment->name]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.environment-edit');
}
}