Files
ladill-transfer/app/Http/Controllers/Transfer/AnalyticsController.php
T
isaaccladandCursor c1e3d8b3ac Initial Ladill Transfer app — file sharing with QR links.
Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers,
retention controls, public landing pages, analytics, and Gitea deploy workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 09:25:30 +00:00

47 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Transfer;
use App\Http\Controllers\Controller;
use App\Models\Transfer;
use App\Models\TransferDownloadEvent;
use Illuminate\Http\Request;
use Illuminate\View\View;
class AnalyticsController extends Controller
{
public function index(Request $request): View
{
$account = ladill_account();
$transferIds = Transfer::query()
->where('user_id', $account->id)
->pluck('id');
$downloads30d = TransferDownloadEvent::query()
->whereIn('transfer_id', $transferIds)
->where('downloaded_at', '>=', now()->subDays(30))
->count();
$topTransfers = Transfer::query()
->where('user_id', $account->id)
->where('status', Transfer::STATUS_ACTIVE)
->orderByDesc('downloads_total')
->limit(10)
->get();
$recentDownloads = TransferDownloadEvent::query()
->whereIn('transfer_id', $transferIds)
->with(['transfer', 'file'])
->latest('downloaded_at')
->limit(20)
->get();
return view('transfer.analytics.index', [
'downloads30d' => $downloads30d,
'topTransfers' => $topTransfers,
'recentDownloads' => $recentDownloads,
]);
}
}