-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathShow.php
More file actions
66 lines (49 loc) · 1.73 KB
/
Show.php
File metadata and controls
66 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace App\Livewire\Customer\Licenses;
use App\Actions\Licenses\RotateLicenseKey;
use App\Models\License;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Attributes\Validate;
use Livewire\Component;
#[Layout('components.layouts.dashboard')]
#[Title('License Details')]
class Show extends Component
{
public License $license;
public bool $showEditNameModal = false;
#[Validate('nullable|string|max:255')]
public ?string $licenseName = null;
public function mount(string $licenseKey): void
{
$this->license = auth()->user()->licenses()
->with('subLicenses')
->where('key', $licenseKey)
->firstOrFail();
$this->licenseName = $this->license->name;
}
public function updateLicenseName(): void
{
$this->validate();
$this->license->update([
'name' => $this->licenseName ?: null,
]);
$this->license->refresh();
$this->showEditNameModal = false;
session()->flash('success', 'License name updated successfully!');
}
public function rotateLicenseKey(RotateLicenseKey $action): void
{
if ($this->license->is_suspended || ($this->license->expires_at && $this->license->expires_at->isPast())) {
session()->flash('error', 'Cannot rotate a suspended or expired license key.');
return;
}
$action->handle($this->license);
session()->flash('success', 'Your license key has been rotated. Please update any applications using the old key.');
$this->redirectRoute('customer.licenses.show', $this->license->key);
}
public function render()
{
return view('livewire.customer.licenses.show');
}
}