Files
ABSDEV/Modules/Licensing/Http/Controllers/Admin/LicensingDashboardController.php
T
2026-10-12 14:50:13 +01:00

57 lines
2.0 KiB
PHP

<?php
namespace Modules\Licensing\Http\Controllers\Admin;
use Illuminate\Contracts\View\View;
use Illuminate\Routing\Controller;
use Modules\Licensing\Models\License;
use Modules\Licensing\Models\LicenseProduct;
final class LicensingDashboardController extends Controller
{
public function index(): View
{
return view('licensing::admin.index', [
'licenseCount' => License::query()->count(),
'activeCount' => License::query()->whereNull('revoked_at')->where(function ($q): void {
$q->whereNull('expires_at')->orWhere('expires_at', '>', now());
})->count(),
'productCount' => LicenseProduct::query()->count(),
'recentLicenses' => License::query()->with('product')->latest()->limit(10)->get(),
]);
}
public function licenses(): View
{
return view('licensing::admin.licenses', [
'licenses' => License::query()->with('product')->latest()->paginate(25),
]);
}
public function show(License $license): View
{
return view('licensing::admin.show', [
'license' => $license->load(['product', 'activations']),
]);
}
/** Read-only snapshot of existing licensing subscription metadata. */
public function subscriptions(): View
{
$subscriptions = License::query()
->whereNotNull('external_subscription_id')
->with('product')
->orderByDesc('created_at')
->paginate(25);
$total = License::query()->whereNotNull('external_subscription_id')->count();
$active = License::query()->whereNotNull('external_subscription_id')
->whereIn('subscription_status', ['active', 'trialing'])->count();
$cancelScheduled = License::query()->whereNotNull('external_subscription_id')
->whereNotNull('cancel_scheduled_at')->count();
return view('licensing::admin.subscriptions', compact('subscriptions', 'total', 'active', 'cancelScheduled'));
}
}