fix: [hr] 사원 등록 시 user_tenants pivot 연동 추가

- User 생성 후 tenants()->attach() 호출 (멀티테넌트 필수)
- user_id, must_change_password, created_by 필드 추가
- 기존 UserService 패턴과 동일하게 맞춤
This commit is contained in:
김보곤
2026-02-26 16:53:32 +09:00
parent 29ca022321
commit 3ce980a5f7

View File

@@ -93,13 +93,25 @@ public function createEmployee(array $data): Employee
return DB::transaction(function () use ($data, $tenantId) {
// User 생성
$user = User::create([
'user_id' => $data['email'] ?? $data['name'],
'name' => $data['name'],
'email' => $data['email'] ?? null,
'phone' => $data['phone'] ?? null,
'password' => bcrypt($data['password'] ?? 'sam1234!'),
'is_active' => true,
'must_change_password' => true,
'created_by' => auth()->id(),
]);
// user_tenants pivot 연동 (멀티테넌트 필수)
if ($tenantId) {
$user->tenants()->attach($tenantId, [
'is_active' => true,
'is_default' => true,
'joined_at' => now(),
]);
}
// json_extra 구성
$jsonExtra = [];
if (! empty($data['employee_code'])) {