lasthourcloud/app/Http/Livewire/PrivateKey/Create.php

34 lines
932 B
PHP
Raw Normal View History

2023-05-03 10:38:57 +00:00
<?php
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
2023-05-04 07:11:11 +00:00
use Illuminate\Support\Facades\Route;
2023-05-03 10:38:57 +00:00
use Livewire\Component;
class Create extends Component
{
2023-05-16 09:39:18 +00:00
protected string|null $from = null;
2023-05-12 13:39:07 +00:00
public string $name;
2023-05-15 12:54:03 +00:00
public string|null $description = null;
2023-05-12 13:39:07 +00:00
public string $value;
2023-05-04 07:11:11 +00:00
2023-05-03 10:38:57 +00:00
public function createPrivateKey()
{
2023-05-12 13:39:07 +00:00
$this->value = trim($this->value);
if (!str_ends_with($this->value, "\n")) {
$this->value .= "\n";
2023-05-03 10:38:57 +00:00
}
2023-05-16 09:39:18 +00:00
$private_key = PrivateKey::create([
2023-05-12 13:39:07 +00:00
'name' => $this->name,
'description' => $this->description,
'private_key' => $this->value,
2023-05-03 10:38:57 +00:00
'team_id' => session('currentTeam')->id
]);
2023-05-16 09:39:18 +00:00
if ($this->from === 'server') {
return redirect()->route('server.new');
}
return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]);
2023-05-03 10:38:57 +00:00
}
}