/**
  * Generates teachers
  * @param int $amount
  */
 protected function _generateTeachers($amount)
 {
     $phonePrefix = rand(100000, 999999);
     for ($i = 0, $j = $amount; $i !== $j; $i++) {
         $data = ['name' => $this->_getName() . '-' . $i, 'sex' => 1, 'phone' => $phonePrefix . '-' . $i];
         $t = new Teacher($data);
         try {
             $t->validate();
             $t->save();
         } catch (\Exception $e) {
             // do nothing
         }
     }
 }
Example #2
0
 $rest->post('/teachers', function (Request $req) use($app) {
     $data = $req->request->all();
     $teacher = new Teacher($data);
     try {
         $teacher->validate();
         $teacher->save();
         return $app->json($teacher, 201);
     } catch (\Models\ValidationException $e) {
         return $app->json(['errors' => $e->getErrors()], 400);
     }
 });
 /**
  * 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) {