lasthourcloud/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2023-05-05 07:28:00 +00:00
<?php
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
use App\Models\Application;
2023-05-05 12:20:10 +00:00
use App\Models\EnvironmentVariable;
2023-05-05 07:28:00 +00:00
use Livewire\Component;
2023-07-13 11:16:24 +00:00
use Visus\Cuid2\Cuid2;
2023-05-05 07:28:00 +00:00
class All extends Component
{
public Application $application;
2023-07-13 11:16:24 +00:00
public string|null $modalId = null;
2023-05-05 12:20:10 +00:00
protected $listeners = ['refreshEnvs', 'submit'];
2023-07-13 11:16:24 +00:00
public function mount()
{
$this->modalId = new Cuid2(7);
}
2023-05-05 07:28:00 +00:00
public function refreshEnvs()
{
$this->application->refresh();
}
2023-05-05 12:20:10 +00:00
public function submit($data)
{
try {
2023-07-13 11:16:24 +00:00
$found = $this->application->environment_variables()->where('key', $data['key'])->first();
if ($found) {
$this->emit('error', 'Environment variable already exists.');
return;
}
2023-05-05 12:20:10 +00:00
EnvironmentVariable::create([
'key' => $data['key'],
'value' => $data['value'],
'is_build_time' => $data['is_build_time'],
2023-06-05 10:07:55 +00:00
'is_preview' => $data['is_preview'],
2023-05-05 12:20:10 +00:00
'application_id' => $this->application->id,
]);
$this->application->refresh();
2023-06-22 08:04:39 +00:00
$this->emit('success', 'Environment variable added successfully.');
2023-05-05 12:20:10 +00:00
} catch (\Exception $e) {
2023-06-09 13:55:21 +00:00
return general_error_handler(err: $e, that: $this);
2023-05-05 12:20:10 +00:00
}
}
2023-05-05 07:28:00 +00:00
}