Пример #1
0
             $job = new Occupation();
             $job->name = $app->request->post('title');
             $job->description = $app->request->post('description');
             $job->youtube = $urlvars['v'];
             $job->educationLevel()->associate($edu_level);
             $job->talent()->associate($talent);
             $job->save();
             $data['new_occupation'] = $job;
         }
     }
     $app->render('occupations/new.html', $data);
 })->via('GET', 'POST')->name('occupations_new');
 $app->map('/edit/:id', function ($id) use($app, $data) {
     $data['request_method'] = $app->request->getMethod();
     if ($app->request->isGet()) {
         $data['occupation'] = Occupation::with('talent', 'educationLevel')->find($id);
         $data['education_levels'] = EducationLevel::NoSchoolAdvice()->get();
         $data['talents'] = Talent::all();
     } else {
         if ($app->request->isPost()) {
             $edu_level = EducationLevel::find($app->request->post('educationlevel'));
             $talent = Talent::find($app->request->post('talent'));
             parse_str(parse_url($app->request->post('yt-video'), PHP_URL_QUERY), $urlvars);
             $job = Occupation::find($id);
             $job->name = $app->request->post('title');
             $job->description = $app->request->post('description');
             $job->youtube = $urlvars['v'];
             $job->educationLevel()->associate($edu_level);
             $job->talent()->associate($talent);
             $job->save();
             $data['new_occupation'] = $job;
Пример #2
0
        $app->halt(401, 'no token');
    }
    try {
        $user = User::with('occupations')->whereHas('token', function ($q) use($token_key) {
            $q->where('key', '=', $token_key);
        })->firstOrFail();
    } catch (ModelNotFoundException $e) {
        $app->halt(401, 'Gebruiker niet gevonden');
    }
    $talent_ids = array();
    foreach ($user->talents as $talent) {
        if ($talent->pivot->picked) {
            array_push($talent_ids, $talent->id);
        }
    }
    $jobs = Occupation::with('educationLevel')->whereIn('talent_id', $talent_ids)->get();
    echo $jobs->toJson();
});
$app->get('/user/schooladvice', function () use($app) {
    $app->response()->header('Content-Type', 'application/json');
    $token_key = $app->request->headers->get('Authorization');
    if (!$token_key) {
        $app->halt(401, 'no token');
    }
    try {
        $user = User::with('educationLevel')->whereHas('token', function ($q) use($token_key) {
            $q->where('key', '=', $token_key);
        })->firstOrFail();
    } catch (ModelNotFoundException $e) {
        $app->halt(401, 'Gebruiker niet gevonden');
    }