nimuli/app/Livewire/Modals/CreateQrCode.php

53 lines
1.1 KiB
PHP

<?php
namespace App\Livewire\Modals;
use App\Domains\QrCode\Models\QrCode;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class CreateQrCode extends ModalComponent
{
public string $label = '';
public string $url = '';
public string $type = 'url';
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');
QrCode::create([
'workspace_id' => $workspace->id,
'type' => $this->type,
'payload' => ['url' => $this->url],
'is_dynamic' => true,
]);
$this->dispatch('qrCreated');
$this->dispatch('toast', message: 'QR Code erstellt', type: 'success');
$this->closeModal();
}
public static function modalMaxWidth(): string
{
return 'md';
}
public function render(): View
{
return view('livewire.modals.create-qr-code');
}
}