feat: [users] 사용자 수정 화면에 소속 부서 선택 기능 추가
- UserController: profile 쿼리에 department_id 추가 - edit.blade.php: 소속 부서 select 드롭다운 UI 추가 - UpdateUserRequest: department_id 유효성 검증 규칙 추가 - UserService: tenant_user_profiles에 department_id 저장 로직 추가
This commit is contained in:
@@ -91,7 +91,7 @@ public function edit(int $id): View
|
||||
? DB::table('tenant_user_profiles')
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('user_id', $user->id)
|
||||
->first(['position_key', 'job_title_key', 'employee_status'])
|
||||
->first(['position_key', 'job_title_key', 'employee_status', 'department_id'])
|
||||
: null;
|
||||
|
||||
return view('users.edit', compact('user', 'roles', 'departments', 'userRoleIds', 'userDepartmentIds',
|
||||
|
||||
@@ -71,6 +71,7 @@ public function rules(): array
|
||||
'position_key' => 'nullable|string|max:64',
|
||||
'job_title_key' => 'nullable|string|max:64',
|
||||
'employee_status' => 'nullable|in:active,leave,resigned',
|
||||
'department_id' => 'nullable|integer|exists:departments,id',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -280,6 +280,9 @@ public function updateUser(int $id, array $data): bool
|
||||
if (array_key_exists('employee_status', $data)) {
|
||||
$profileFields['employee_status'] = $data['employee_status'] ?: 'active';
|
||||
}
|
||||
if (array_key_exists('department_id', $data)) {
|
||||
$profileFields['department_id'] = $data['department_id'] ?: null;
|
||||
}
|
||||
if (! empty($profileFields)) {
|
||||
DB::table('tenant_user_profiles')->updateOrInsert(
|
||||
['tenant_id' => $tenantId, 'user_id' => $id],
|
||||
@@ -289,7 +292,7 @@ public function updateUser(int $id, array $data): bool
|
||||
}
|
||||
|
||||
// role_ids, department_ids, position/job_title은 User 모델의 fillable이 아니므로 제거
|
||||
unset($data['role_ids'], $data['department_ids'], $data['position_key'], $data['job_title_key'], $data['employee_status']);
|
||||
unset($data['role_ids'], $data['department_ids'], $data['position_key'], $data['job_title_key'], $data['employee_status'], $data['department_id']);
|
||||
|
||||
return $user->update($data);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,23 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 소속 -->
|
||||
<div class="mb-8">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">소속</h2>
|
||||
<div style="max-width: 400px;">
|
||||
<select name="department_id"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
||||
<option value="">선택하세요</option>
|
||||
@foreach($departments as $dept)
|
||||
<option value="{{ $dept->id }}" {{ ($profile?->department_id ?? '') == $dept->id ? 'selected' : '' }}>
|
||||
{{ $dept->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<p class="text-xs text-gray-500 mt-1">결재선, 인사 관리 등에서 사용되는 소속 부서입니다.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 직급/직책 -->
|
||||
<div class="mb-8">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">직급/직책</h2>
|
||||
|
||||
Reference in New Issue
Block a user