coolify/app/Http/Livewire/PrivateKey/Change.php

42 lines
1.3 KiB
PHP
Raw Normal View History

2023-05-03 12:38:57 +02:00
<?php
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Livewire\Component;
class Change extends Component
{
2023-05-03 14:24:18 +02:00
public string $private_key_uuid;
public PrivateKey $private_key;
2023-05-03 12:38:57 +02:00
2023-05-03 14:24:18 +02:00
protected $rules = [
'private_key.name' => 'required|string',
'private_key.description' => 'nullable|string',
'private_key.private_key' => 'required|string'
];
public function mount()
{
$this->private_key = PrivateKey::where('uuid', $this->private_key_uuid)->first();
}
2023-05-04 15:45:53 +02:00
public function delete()
2023-05-03 12:38:57 +02:00
{
2023-05-04 15:45:53 +02:00
PrivateKey::where('uuid', $this->private_key_uuid)->delete();
2023-05-03 12:38:57 +02:00
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
redirect()->route('dashboard');
}
public function changePrivateKey()
{
try {
2023-05-03 14:24:18 +02:00
$this->private_key->private_key = trim($this->private_key->private_key);
if (!str_ends_with($this->private_key->private_key, "\n")) {
$this->private_key->private_key .= "\n";
2023-05-03 12:38:57 +02:00
}
2023-05-03 14:24:18 +02:00
$this->private_key->save();
2023-05-03 12:38:57 +02:00
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
} catch (\Exception $e) {
2023-06-09 15:55:21 +02:00
return general_error_handler(err: $e, that: $this);
2023-05-03 12:38:57 +02:00
}
}
}