コード例 #1
0
 public static function create(array $attributes = [])
 {
     $employee = new HospitalEmployee();
     $employee->firstname = $attributes['firstname'];
     $employee->lastname = $attributes['lastname'];
     $employee->tel = $attributes['tel'];
     $employee->email = $attributes['email'];
     $employee->role = $attributes['role'];
     if ($attributes['role'] == 'Doctor') {
         $employee->specialty = $attributes['specialty'];
     }
     $employee->valid = false;
     $employee->save();
     // this will also create the User for authentication
     $user = new User();
     // duplicate personal id to username
     $user->username = $attributes['username'];
     $user->password = Hash::make($attributes['password']);
     $user->userable_id = $employee->emp_id;
     $user->userable_type = 'App\\HospitalEmployee';
     $user->save();
     return $employee;
 }