coolify/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2023-05-04 22:29:14 +02:00
<?php
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
use App\Models\Application;
use App\Models\EnvironmentVariable;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class Add extends Component
{
public $parameters;
public string $key;
public string $value;
public bool $is_build_time = false;
2023-05-05 09:28:00 +02:00
protected $rules = [
'key' => 'required|string',
'value' => 'required|string',
'is_build_time' => 'required|boolean',
];
2023-05-04 22:29:14 +02:00
public function mount()
{
$this->parameters = Route::current()->parameters();
}
public function submit()
{
2023-05-05 09:28:00 +02:00
$this->validate();
2023-05-04 22:29:14 +02:00
try {
$application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
EnvironmentVariable::create([
'key' => $this->key,
'value' => $this->value,
'is_build_time' => $this->is_build_time,
'application_id' => $application_id,
]);
2023-05-05 09:28:00 +02:00
$this->emit('refreshEnvs');
$this->key = '';
$this->value = '';
2023-05-04 22:29:14 +02:00
} catch (mixed $e) {
dd('asdf');
if ($e instanceof QueryException) {
dd($e->errorInfo);
$this->emit('error', $e->errorInfo[2]);
} else {
$this->emit('error', $e);
}
}
}
}