$app->group('/skills', function () use($app, $data) { $data['request_method'] = $app->request->getMethod(); $app->get('/', function () use($app, $data) { $data['skills'] = Skill::all(); $app->render('skills/overview.html', $data); })->name('skills_overview'); $app->map('/delete/:id', function ($id) use($app, $data) { $data['skill'] = Skill::find($id); if ($app->request->isPost()) { $data['skill']->delete(); } $app->render('skills/delete.html', $data); })->via('GET', 'POST')->name('skills_delete'); $app->map('/new', function () use($app, $data) { if ($app->request->isPost()) { $edu_level = EducationLevel::find($app->request->post('educationlevel')); $skill = new Skill(); $skill->name = $app->request->post('title'); $skill->save(); $data['new_skill'] = $skill; } $app->render('skills/new.html', $data); })->via('GET', 'POST')->name('skills_new'); $app->map('/edit/:id', function ($id) use($app, $data) { $data['request_method'] = $app->request->getMethod(); $skill = Skill::find($id); if ($app->request->isGet()) { $data['skill'] = $skill->toArray(); } else { if ($app->request->isPost()) { $skill->name = $app->request->post('title');
$app->response()->header('Content-Type', 'application/json'); $req_body = json_decode($app->request->getBody()); // Check if all fields are present if ($req_body->gender == NULL || $req_body->nickname == NULL || $req_body->password1 == NULL || $req_body->password2 == NULL || $req_body->school == NULL) { $app->halt(400, '{"message": "er is iets fout gegeaan"}'); } // Check if username exists if (User::where('nickname', 'like', $req_body->nickname)->count()) { $app->halt(400, 'nickname_exists'); } try { $user = new User(); $user->nickname = $req_body->nickname; $user->gender = $req_body->gender; $user->password = sha1($req_body->password1); $user->educationLevel()->associate(EducationLevel::find((int) $req_body->schoolAdvice)); $user->school()->associate(School::find((int) $req_body->school)); $user->save(); // Create token $token = new Token(); $token->generateToken(); $token->user()->associate($user); $token->save(); } catch (Exception $e) { $app->halt(500, 'something_went_wrong'); } echo $token->toJson(); }); $app->get('/user', function () use($app) { $app->response()->header('Content-Type', 'application/json'); $token_key = $app->request->headers->get('Authorization');