auditionCacheService = $scoringGuideCacheService; } public function getScoredEntries() { return Cache::remember($this->cacheKey, 10, function () { $entries = Entry::with(['scoreSheets'])->get(); return $entries->keyBy('id'); }); } public function getAuditionsWithStatus() { $scoreCountByEntry = DB::table('score_sheets') ->select('entry_id', DB::raw('count(*) as count')) ->groupBy('entry_id') ->get() ->pluck('count','entry_id'); $auditions = $this->auditionCacheService->getAuditions(); $auditions->load(['entries' => function ($query) { $query->select('id'); }]); $auditions->loadCount('judges'); $auditions->loadCount('entries'); foreach ($auditions as $audition) { // Get the count of entries that have been scored $audition->scored_entries = $audition->entries->filter(function ($entry) use ($scoreCountByEntry) { return $entry->score_sheets_count == $scoreCountByEntry[$entry->id]; }); // WHY WILL THIS NOT WORK????? } return $auditions; } }