public function getMatchCountAttribute() { $skill_ids = []; foreach ($this->job_skills as $job_skill) { $skill_ids[] = $job_skill['skill_id']; } if (count($skill_ids) > 0) { $user_ids = UserSkill::select(DB::raw('DISTINCT(user_id)'))->whereIn('skill_id', $skill_ids)->get()->toArray(); $lat = $this->job_locations->lat; $lng = $this->job_locations->lng; $users = User::within((int) $this->search_radius, 'kilometers', $lat, $lng)->where('lat', '!=', '')->where('lng', '!=', '')->whereIn('id', $user_ids)->get(); return count($users); } return 0; }
public function getJobMatches($job_id) { try { $company_job = CompanyJob::with('job_skills', 'job_locations')->where('post_status', '=', 'published')->where('id', '=', $job_id)->where('end_date', '>=', date('Y-m-d'))->first()->toArray(); $job_skill_ids = []; foreach ($company_job['job_skills'] as $skill) { $job_skill_ids[] = $skill['skill_id']; } $users = []; if (count($job_skill_ids) > 0) { $user_ids = UserSkill::select(DB::raw('DISTINCT(user_id)'))->whereIn('skill_id', $job_skill_ids)->get()->toArray(); $lat = $company_job['job_locations']['lat']; $lng = $company_job['job_locations']['lng']; $users = User::within((int) $company_job['search_radius'], 'kilometers', $lat, $lng)->where('lat', '!=', '')->where('lng', '!=', '')->whereIn('id', $user_ids)->get(); } return $users; } catch (Exception $e) { return Response::json(['error' => $e->getMessage()]); } }