lasthourcloud/app/Http/Livewire/PrivateKey/Create.php
2023-05-12 15:39:07 +02:00

38 lines
1.0 KiB
PHP

<?php
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class Create extends Component
{
public string $name;
public string|null $description;
public string $value;
public string $currentRoute;
public function mount()
{
$this->currentRoute = Route::current()->uri();
}
public function createPrivateKey()
{
$this->value = trim($this->value);
if (!str_ends_with($this->value, "\n")) {
$this->value .= "\n";
}
$new_private_key = PrivateKey::create([
'name' => $this->name,
'description' => $this->description,
'private_key' => $this->value,
'team_id' => session('currentTeam')->id
]);
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
if ($this->currentRoute !== 'server/new') {
redirect()->route('private-key.show', $new_private_key->uuid);
}
}
}