diff --git a/app/Http/Controllers/Mini/PaymentQrController.php b/app/Http/Controllers/Mini/PaymentQrController.php index db79985..b26e231 100644 --- a/app/Http/Controllers/Mini/PaymentQrController.php +++ b/app/Http/Controllers/Mini/PaymentQrController.php @@ -101,6 +101,17 @@ class PaymentQrController extends Controller return back()->with('success', 'Payment QR updated.'); } + public function destroy(QrCode $paymentQr): RedirectResponse + { + $this->authorizePaymentQr($paymentQr); + + $this->manager->delete($paymentQr); + + return redirect() + ->route('mini.payment-qrs.index') + ->with('success', 'Payment QR deleted.'); + } + public function preview(QrCode $paymentQr): Response { $this->authorizePaymentQr($paymentQr); diff --git a/app/Services/Qr/QrCodeManagerService.php b/app/Services/Qr/QrCodeManagerService.php index b76bdea..29f6df2 100644 --- a/app/Services/Qr/QrCodeManagerService.php +++ b/app/Services/Qr/QrCodeManagerService.php @@ -536,4 +536,20 @@ class QrCodeManagerService throw new RuntimeException('Could not generate a unique QR short code.'); } + + public function delete(QrCode $qrCode): void + { + $paths = array_filter([$qrCode->png_path, $qrCode->svg_path]); + + $logoPath = $qrCode->content()['logo_path'] ?? null; + if (is_string($logoPath) && $logoPath !== '') { + $paths[] = $logoPath; + } + + foreach ($paths as $path) { + Storage::disk('qr')->delete($path); + } + + $qrCode->delete(); + } } diff --git a/resources/views/mini/payment-qrs/index.blade.php b/resources/views/mini/payment-qrs/index.blade.php index a61e49c..d8a0021 100644 --- a/resources/views/mini/payment-qrs/index.blade.php +++ b/resources/views/mini/payment-qrs/index.blade.php @@ -8,6 +8,9 @@ New payment QR + @if(session('success')) +
{{ session('success') }}
+ @endif @if($qrCodes->isEmpty())

No payment QRs yet.

diff --git a/resources/views/mini/payment-qrs/show.blade.php b/resources/views/mini/payment-qrs/show.blade.php index 63847f1..266bddc 100644 --- a/resources/views/mini/payment-qrs/show.blade.php +++ b/resources/views/mini/payment-qrs/show.blade.php @@ -40,6 +40,7 @@

{{ $qrCode->publicUrl() }}

+
@csrf @method('PATCH') @@ -62,6 +63,18 @@
+ +
+

Delete payment QR

+

Removes this QR and its payment link. Scans will stop working. This cannot be undone.

+
+ @csrf + @method('DELETE') + +
+
+
diff --git a/routes/web.php b/routes/web.php index 9fd2398..0fcac6e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,6 +43,7 @@ Route::middleware(['auth'])->group(function () { Route::post('/payment-qrs', [PaymentQrController::class, 'store'])->name('mini.payment-qrs.store'); Route::get('/payment-qrs/{paymentQr}', [PaymentQrController::class, 'show'])->name('mini.payment-qrs.show'); Route::patch('/payment-qrs/{paymentQr}', [PaymentQrController::class, 'update'])->name('mini.payment-qrs.update'); + Route::delete('/payment-qrs/{paymentQr}', [PaymentQrController::class, 'destroy'])->name('mini.payment-qrs.destroy'); Route::get('/payment-qrs/{paymentQr}/preview.png', [PaymentQrController::class, 'preview'])->name('mini.payment-qrs.preview'); Route::get('/payment-qrs/{paymentQr}/download/{format}', [PaymentQrController::class, 'download'])->name('mini.payment-qrs.download')->whereIn('format', ['png', 'svg', 'pdf']);