70 lines
1.6 KiB
PHP
70 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Domains\QrCode\Models\QrCode;
|
|
use Illuminate\View\View;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class EditQrCode extends ModalComponent
|
|
{
|
|
public string $qrUlid = '';
|
|
|
|
public string $url = '';
|
|
|
|
public string $label = '';
|
|
|
|
public string $type = 'url';
|
|
|
|
public function mount(string $qrUlid): void
|
|
{
|
|
$workspace = app('current_workspace');
|
|
$qr = QrCode::where('ulid', $qrUlid)
|
|
->where('workspace_id', $workspace->id)
|
|
->firstOrFail();
|
|
|
|
$this->qrUlid = $qrUlid;
|
|
$this->url = $qr->payload['url'] ?? '';
|
|
$this->label = $qr->label ?? '';
|
|
$this->type = $qr->type;
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'url' => 'required|url|max:2048',
|
|
'label' => 'nullable|max:200',
|
|
'type' => 'required|in:url,vcard,wifi,pdf,mp3,text',
|
|
];
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$this->validate();
|
|
$workspace = app('current_workspace');
|
|
|
|
$qr = QrCode::where('ulid', $this->qrUlid)
|
|
->where('workspace_id', $workspace->id)
|
|
->firstOrFail();
|
|
|
|
$qr->update([
|
|
'type' => $this->type,
|
|
'payload' => ['url' => $this->url],
|
|
]);
|
|
|
|
$this->dispatch('qrUpdated', qrUlid: $this->qrUlid);
|
|
$this->dispatch('toast', message: 'QR Code aktualisiert', type: 'success');
|
|
$this->closeModal();
|
|
}
|
|
|
|
public static function modalMaxWidth(): string
|
|
{
|
|
return 'md';
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.modals.edit-qr-code');
|
|
}
|
|
}
|