2025-11-24 18:49:02 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
|
|
class UpdateUserRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 23:05:07 +09:00
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
* 일반관리자가 슈퍼관리자 관련 필드를 변경하려는 경우 처리
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$userId = $this->route('id');
|
|
|
|
|
$targetUser = \App\Models\User::find($userId);
|
|
|
|
|
$currentUser = auth()->user();
|
|
|
|
|
|
|
|
|
|
// 슈퍼관리자가 아닌 경우
|
|
|
|
|
if (! $currentUser?->is_super_admin) {
|
|
|
|
|
// is_super_admin 필드가 있으면 제거 (기존 값 유지)
|
|
|
|
|
if ($this->has('is_super_admin')) {
|
|
|
|
|
$this->merge([
|
|
|
|
|
'is_super_admin' => $targetUser?->is_super_admin ?? false,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 18:49:02 +09:00
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$userId = $this->route('id');
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'user_id' => [
|
|
|
|
|
'nullable',
|
|
|
|
|
'string',
|
|
|
|
|
'max:50',
|
|
|
|
|
Rule::unique('users', 'user_id')->ignore($userId),
|
|
|
|
|
],
|
|
|
|
|
'name' => 'required|string|max:100',
|
|
|
|
|
'email' => [
|
|
|
|
|
'required',
|
|
|
|
|
'email',
|
|
|
|
|
'max:255',
|
|
|
|
|
Rule::unique('users', 'email')->ignore($userId),
|
|
|
|
|
],
|
|
|
|
|
'phone' => 'nullable|string|max:20',
|
|
|
|
|
'password' => 'nullable|string|min:8|confirmed',
|
|
|
|
|
'role' => 'nullable|string|max:50',
|
|
|
|
|
'is_active' => 'nullable|boolean',
|
|
|
|
|
'is_super_admin' => 'nullable|boolean',
|
2025-11-26 20:28:07 +09:00
|
|
|
'role_ids' => 'nullable|array',
|
|
|
|
|
'role_ids.*' => 'integer|exists:roles,id',
|
|
|
|
|
'department_ids' => 'nullable|array',
|
|
|
|
|
'department_ids.*' => 'integer|exists:departments,id',
|
2026-02-28 08:07:21 +09:00
|
|
|
'position_key' => 'nullable|string|max:64',
|
|
|
|
|
'job_title_key' => 'nullable|string|max:64',
|
2026-02-28 08:23:16 +09:00
|
|
|
'employee_status' => 'nullable|in:active,leave,resigned',
|
2025-11-24 18:49:02 +09:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'user_id' => '사용자 ID',
|
|
|
|
|
'name' => '이름',
|
|
|
|
|
'email' => '이메일',
|
|
|
|
|
'phone' => '연락처',
|
|
|
|
|
'password' => '비밀번호',
|
|
|
|
|
'password_confirmation' => '비밀번호 확인',
|
|
|
|
|
'role' => '역할',
|
|
|
|
|
'is_active' => '활성 상태',
|
|
|
|
|
'is_super_admin' => '슈퍼 관리자',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom messages for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'email.unique' => '이미 사용 중인 이메일입니다.',
|
|
|
|
|
'user_id.unique' => '이미 사용 중인 사용자 ID입니다.',
|
|
|
|
|
'password.confirmed' => '비밀번호가 일치하지 않습니다.',
|
|
|
|
|
'password.min' => '비밀번호는 최소 8자 이상이어야 합니다.',
|
|
|
|
|
];
|
|
|
|
|
}
|
2025-11-25 11:06:03 +09:00
|
|
|
}
|