*/ public function fetchStaffPositions(): Collection { $cacheEnabled = setting('enable_caching') === '1'; if ($cacheEnabled && Cache::has('staff_positions')) { /** @var Collection */ return Cache::get('staff_positions'); } /** @var \App\Models\User|null $user */ $user = Auth::user(); $userRank = $user ? $user->rank : 0; /** @var Collection $employees */ $employees = Permission::query() ->select('id', 'rank_name', 'badge', 'staff_color', 'job_description') ->when($userRank < (int) setting('min_rank_to_see_hidden_staff'), fn ($query) => $query->where('hidden_rank', false)) ->where('id', '>=', setting('min_staff_rank')) ->orderByDesc('id') ->with(['users' => function ($query) use ($userRank): void { /** @var \Illuminate\Database\Eloquent\Builder $query */ $query->select('id', 'username', 'rank', 'motto', 'look', 'hidden_staff', 'online') ->when($userRank < (int) setting('min_rank_to_see_hidden_staff'), fn ($query) => $query->where('hidden_staff', false)); }]) ->get(); if ($cacheEnabled) { $cacheTimer = (int) setting('cache_timer'); Cache::put('staff_positions', $employees, now()->addMinutes($cacheTimer)); } return $employees; } /** * @return array */ public function fetchEmployeeIds(): array { $cacheEnabled = setting('enable_caching') === '1'; if ($cacheEnabled && Cache::has('staff_ids')) { /** @var array */ return Cache::get('staff_ids'); } /** @var array $staffIds */ $staffIds = User::select('id') ->where('rank', '>=', setting('min_staff_rank')) ->get() ->pluck('id')->toArray(); if ($cacheEnabled) { $cacheTimer = (int) setting('cache_timer'); Cache::put('staff_ids', $staffIds, now()->addMinutes($cacheTimer)); } return $staffIds; } }