Files
ladill-qr-plus/app/Http/Controllers/Qr/OverviewController.php
T
isaaccladandClaude Opus 4.8 296312ab4b
Deploy Ladill QR Plus / deploy (push) Successful in 41s
Wire QR overview create-code links into the two-step add-funds modal
The dashboard 'Create code' / 'Create your first code' links were plain hrefs
to the create page, so a user with insufficient balance only met the top-up
modal after filling the form. Gate them with balanceGate + mount the modal so
they open Add funds directly when the wallet can't cover a QR code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 06:37:28 +00:00

64 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Qr;
use App\Http\Controllers\Controller;
use App\Models\QrCode;
use App\Models\QrWallet;
use App\Services\Billing\BillingClient;
use App\Services\Qr\QrCodeManagerService;
use App\Support\Qr\QrTypeCatalog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Throwable;
class OverviewController extends Controller
{
public function __construct(
private QrCodeManagerService $manager,
private BillingClient $billing,
) {}
public function index(Request $request): View
{
$account = ladill_account();
$wallet = $this->manager->walletFor($account);
$codes = $account->qrCodes()
->whereIn('type', QrTypeCatalog::plusTypes())
->latest()
->limit(5)
->get();
$activeCount = $account->qrCodes()
->whereIn('type', QrTypeCatalog::plusTypes())
->where('is_active', true)
->count();
$scans30d = $account->qrCodes()
->whereIn('type', QrTypeCatalog::plusTypes())
->withSum(['scanEvents as scans_30d' => fn ($q) => $q->where('created_at', '>=', now()->subDays(30))], 'id')
->get()
->sum('scans_30d');
$balanceMinor = 0;
try {
$balanceMinor = $this->billing->balanceMinor($account->public_id);
} catch (Throwable $e) {
Log::warning('QR Plus dashboard could not load wallet balance', [
'user' => $account->public_id,
'error' => $e->getMessage(),
]);
}
return view('qr.dashboard', [
'wallet' => $wallet,
'recentCodes' => $codes,
'activeCount' => $activeCount,
'scans30d' => (int) $scans30d,
'balanceMinor' => $balanceMinor,
'pricePerQr' => QrWallet::pricePerQr(),
]);
}
}