Inheritance: extends Domain\BaseModel, use trait Illuminate\Database\Eloquent\SoftDeletes
 /**
  * Associate matters.
  * @param  Teacher $teacher
  * @param  array     $matters
  */
 public function associateMatters(Teacher $teacher, array $matters)
 {
     $ids = [];
     foreach ($matters['matters'] as $matter) {
         $ids[] = $matter['id'];
     }
     $teacher->matters()->sync($ids);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Teacher::truncate();
     factory(Teacher::class, 20)->create();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Beispiel #3
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $id = $this->route('teacher');
     $user_id = 'NULL';
     $teacher = Teacher::find($id);
     $user = $teacher->user;
     if (isset($user)) {
         $user_id = $user->id;
     }
     return ['name' => 'required|max:45', 'sex' => 'required|in:male,female', 'cpf' => 'required|cpf|unique:teachers,cpf,' . $id, 'rg' => 'max:10', 'postcode' => 'required|max:8|regex:/[0-9]/', 'street' => 'required|max:60', 'number' => 'required|max:10', 'district' => 'required|max:60', 'city' => 'required|max:60', 'state' => 'required|max:2', 'phone' => 'required|phone_br', 'cellphone' => 'required|cellphone_br', 'salary' => 'required|positive', 'type_salary' => 'required|in:commission,class_time', 'user' => 'required|array', 'user.username' => 'required|max:30|unique:users,username,' . $user_id . ',id,owner_type,Domain\\Teacher\\Teacher', 'user.email' => 'required|max:255|email|unique:users,email,' . $user_id . ',id,owner_type,Domain\\Teacher\\Teacher', 'status' => 'required|boolean'];
 }
Beispiel #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Schedule::truncate();
     Billet::truncate();
     BilletAssignor::truncate();
     Classroom::truncate();
     ClassroomMatter::truncate();
     Config::truncate();
     Employee::truncate();
     Lesson::truncate();
     Matter::truncate();
     Schedule::truncate();
     Student::truncate();
     Teacher::truncate();
     factory(BilletAssignor::class, 1)->create();
     factory(Billet::class, 5)->create();
     $allClassrooms = factory(Classroom::class, 10)->create();
     factory(ClassroomMatter::class, 10)->create();
     factory(Config::class, 10)->create();
     $employee = factory(Employee::class)->create();
     factory(Lesson::class, 40)->create();
     $matters = factory(Matter::class, 10)->create();
     factory(Schedule::class, 3)->create();
     $student = factory(Student::class)->create();
     $teacher = factory(Teacher::class)->create();
     factory(User::class, 1)->create(['username' => 'funcionario', 'password' => bcrypt('funcionario123'), 'owner_type' => Employee::class, 'owner_id' => $employee->id]);
     factory(User::class, 1)->create(['username' => 'aluno', 'password' => bcrypt('aluno123'), 'owner_type' => Student::class, 'owner_id' => $student->id]);
     factory(User::class, 1)->create(['username' => 'professor', 'password' => bcrypt('professor123'), 'owner_type' => Teacher::class, 'owner_id' => $teacher->id]);
     $classrooms = factory(Classroom::class, 3)->create(['teacher_id' => $teacher->id]);
     $classrooms->each(function ($classroom) use($student, $matters) {
         $classroom->students()->attach($student);
         $matters->random(3)->each(function ($matter) use($classroom) {
             $classroom->matters()->attach($matter);
         });
     });
     $allClassrooms->random(3)->each(function ($classroom) use($student, $matters, $teacher) {
         $classroom->teacher()->associate($teacher);
         $classroom->students()->attach($student);
         $matters->random(3)->each(function ($matter) use($classroom) {
             $classroom->matters()->attach($matter);
         });
     });
     factory(User::class, 30)->create();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     return Teacher::where('id', $this->route('teacher_id'))->exists();
 }