findOrFail($studentId); $company = Company::with('skills')->findOrFail($companyId); // Get the skill IDs as collections $studentSkillIds = $student->skills->pluck('id'); $companySkillIds = $company->skills->pluck('id'); // If either has no skills, return 0% if ($studentSkillIds->isEmpty() || $companySkillIds->isEmpty()) { return 0; } // Count the matching skills $matchingSkillsCount = $studentSkillIds->intersect($companySkillIds)->count(); // Calculate the total unique skills $totalUniqueSkills = $studentSkillIds->union($companySkillIds)->count(); // Score krijgen op hoeveelheid van de student zijn skills overeenkomen $matchPercentage = ($matchingSkillsCount / $studentSkillIds->count()) * 100; // Round to 2 decimal places return round(pow($matchPercentage, 1.1), 2); } }