*/ public const SORTABLE = ['token', 'files_count', 'total_size', 'download_count', 'expires_at', 'created_at']; /** @var array{column: string, direction: string} */ public array $sortBy = ['column' => 'created_at', 'direction' => 'desc']; /** The share the delete dialog is asking about, while it is open. */ public ?int $deletingShareId = null; public function deleteShare(int $shareId, ShareService $shareService): void { $share = Share::query()->findOrFail($shareId); $shareService->deleteShare($share); $this->deletingShareId = null; } public function render(): mixed { $shareService = app(ShareService::class); // The sort comes from the browser: only a known column and direction reach the query. $column = in_array($this->sortBy['column'] ?? null, self::SORTABLE, true) ? $this->sortBy['column'] : 'created_at'; $direction = ($this->sortBy['direction'] ?? null) === 'asc' ? 'asc' : 'desc'; $shares = Share::query() ->withCount('files') ->orderBy($column, $direction) ->paginate(15); return view('livewire.admin.admin-dashboard', [ 'shares' => $shares, 'totalShares' => Share::query()->count(), 'activeShares' => Share::query()->where(function ($q) { $q->whereNull('expires_at')->orWhere('expires_at', '>', now()); })->count(), 'totalFiles' => ShareFile::query()->count(), 'usedSpace' => $shareService->getTotalUsedSpace(), 'maxQuota' => $shareService->getMaxStorageQuota(), ]); } }