public function searchjob() { $skillids = array(); $skilllist = json_decode(\Input::get("skills"), true); foreach ($skilllist as $d) { $skillids[] = (int) $d["value"]; } $latitude = \Input::get('location_latitude'); $longitude = \Input::get('location_longitude'); $skilbaseids = DB::table('skill_to_job')->whereIn("skill_id", $skillids)->lists('job_id'); $joball = \Motibu\Models\Job::all(); $jobIds = array(); foreach ($joball as $key => $d) { // $distance = getDistance($latitude,$longitude,$d->location_latitude,$d->location_longitude); $earth_radius = 6371; $dLat = deg2rad($d->location_latitude - $latitude); $dLon = deg2rad($d->location_longitude - $longitude); $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latitude)) * cos(deg2rad($d->location_latitude)) * sin($dLon / 2) * sin($dLon / 2); $c = 2 * asin(sqrt($a)); $distance = $earth_radius * $c; if ($distance <= 100) { //print_r($d); $jobIds[] = $d->id; } } if (!empty($jobIds) && !empty($skilbaseids)) { $jobIds = array_intersect($jobIds, $skilbaseids); } elseif (!empty($skilbaseids)) { echo "string"; $jobIds = $skilbaseids; } $jobs = \Motibu\Models\Job::with("skills")->whereIn('id', $jobIds)->paginate(); //return $jobs; return $this->respondWithCollection($jobs, new JobTransformer(), ['skills']); }
/** * Lists Job * @return \Illuminate\Http\JsonResponse */ public function index() { $jobs = Job::with('skills')->paginate(); // $jobs = $paginator->getCollection(); return $this->respondWithCollection($jobs, new JobTransformer(), ['skills']); }