43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\System\Modal;
|
|
|
|
use App\Models\PersonalAccessToken;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class ApiKeyDeleteModal extends ModalComponent
|
|
{
|
|
public int $tokenId;
|
|
public string $tokenName = '';
|
|
|
|
public function mount(int $tokenId): void
|
|
{
|
|
$token = PersonalAccessToken::where('tokenable_id', Auth::id())
|
|
->where('tokenable_type', Auth::user()::class)
|
|
->findOrFail($tokenId);
|
|
|
|
$this->tokenId = $tokenId;
|
|
$this->tokenName = $token->name;
|
|
}
|
|
|
|
public function delete(): void
|
|
{
|
|
PersonalAccessToken::where('tokenable_id', Auth::id())
|
|
->where('tokenable_type', Auth::user()::class)
|
|
->findOrFail($this->tokenId)
|
|
->delete();
|
|
|
|
$this->dispatch('toast', type: 'done', badge: 'API Key',
|
|
title: 'Gelöscht', text: "Key <b>{$this->tokenName}</b> wurde entfernt.", duration: 4000);
|
|
|
|
$this->dispatch('token-deleted');
|
|
$this->closeModal();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.system.modal.api-key-delete-modal');
|
|
}
|
|
}
|