} }); /** * Teachers with april-born students */ $rest->get('/teachers/april-born', function () use($app) { $teachers = Teacher::aprilBornStudents()->get(); return $app->json($teachers); }); /** * Get students */ $rest->get('/students', function () use($app, $modelsToArray) { $limit = $app['request']->get('limit', 10); $offset = $app['request']->get('offset', 0); $students = Student::limit($limit)->offset($offset)->orderBy('created_at', 'desc')->get(); return $app->json($modelsToArray($students, ['level'])); }); /** * Count of students */ $rest->get('/students/count', function () use($app) { $count = Student::all()->count(); return $app->json(['count' => $count]); }); /** * Student by id */ $rest->get('/students/{id}', function ($id) use($app, $modelToArray) { $model = Student::findOrFail($id); return $app->json($modelToArray($model, ['level']));