41 lines
786 B
PHP
41 lines
786 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use Illuminate\View\View;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class CreateApiToken extends ModalComponent
|
|
{
|
|
public string $name = '';
|
|
|
|
public ?string $plainTextToken = null;
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|max:100',
|
|
];
|
|
}
|
|
|
|
public function create(): void
|
|
{
|
|
$this->validate();
|
|
|
|
$token = auth()->user()->createToken($this->name);
|
|
$this->plainTextToken = $token->plainTextToken;
|
|
|
|
$this->dispatch('apiTokenCreated');
|
|
}
|
|
|
|
public static function closeModalOnClickAway(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.modals.create-api-token');
|
|
}
|
|
}
|