public function companiesRankList(Domain $domain, GetTopRankCompanies $request): JsonResponse 	{ 		$ppiSurvey = ClientSurvey::byDomain($domain)->forYear($request->year)->ppiSurveys()->finished()->comparable()->firstOrFail();  		$applicant_count = $ppiSurvey->applicants()->available()->final()->count();  		$companies = Company::available()->whereHas('applicants', function ($query) use ($ppiSurvey) { 			$query 			->whereHas('survey', function ($query) use ($ppiSurvey) { 				$query->where('id', $ppiSurvey->id); 			}) 			->available() 			->final(); 		});  		if (!$companies->exists()) { 			abort(404); 		}  		$top_companies = $companies->withCount([ 			'applicantCompanyPivot as first_place_ranking_count' => function ($query) { 				$query->where('rank', 1); 			}, 			'applicantCompanyPivot as second_place_ranking_count' => function ($query) { 				$query->where('rank', 2); 			}, 			'applicantCompanyPivot as third_place_ranking_count' => function ($query) { 				$query->where('rank', 3); 			}, 		]) 		->orderByRaw('((first_place_ranking_count * 3) + (second_place_ranking_count * 2) + third_place_ranking_count) DESC') 		->limit(10) 		->get();  		return response()->json([ 			'data' => [ 				'start_month' => $ppiSurvey->start_date->format('m'), 				'end_month' => $ppiSurvey->end_date->format('m'), 				'total_applicants' => $applicant_count, 				'top_companies' => $top_companies->pluck('name')->toArray(), 			], 		]); 	}