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\Routing\Route as RoutingRoute;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
2023-05-03 10:38:57 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Create extends Component
|
|
|
|
{
|
|
|
|
public $private_key_value;
|
|
|
|
public $private_key_name;
|
|
|
|
public $private_key_description;
|
2023-05-04 07:11:11 +00:00
|
|
|
public string $currentRoute;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->currentRoute = Route::current()->uri();
|
|
|
|
}
|
2023-05-03 10:38:57 +00:00
|
|
|
public function createPrivateKey()
|
|
|
|
{
|
|
|
|
$this->private_key_value = trim($this->private_key_value);
|
|
|
|
if (!str_ends_with($this->private_key_value, "\n")) {
|
|
|
|
$this->private_key_value .= "\n";
|
|
|
|
}
|
2023-05-03 12:09:10 +00:00
|
|
|
$new_private_key = PrivateKey::create([
|
2023-05-03 10:38:57 +00:00
|
|
|
'name' => $this->private_key_name,
|
|
|
|
'description' => $this->private_key_description,
|
|
|
|
'private_key' => $this->private_key_value,
|
|
|
|
'team_id' => session('currentTeam')->id
|
|
|
|
]);
|
|
|
|
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
2023-05-04 07:11:11 +00:00
|
|
|
if ($this->currentRoute !== 'server/new') {
|
|
|
|
redirect()->route('private-key.show', $new_private_key->uuid);
|
|
|
|
}
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
|
|
|
}
|