Files
ladill-qr-plus/app/Http/Controllers/Qr/OverviewController.php
T
isaaccladandCursor 8c3e9d3c26
Deploy Ladill QR Plus / deploy (push) Successful in 42s
Add team, developers, PDF type, and QR rendering dependency.
Enables account collaboration, API tokens, hosted PDF codes, and fixes QR detail 500s by declaring chillerlan/php-qrcode.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 06:16:13 +00:00

62 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Qr;
use App\Http\Controllers\Controller;
use App\Models\QrCode;
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,
]);
}
}