1
0
Files
services_core/app/Http/Requests/User/UpdateUserRequest.php
T
2026-07-27 16:24:09 +07:00

80 lines
2.8 KiB
PHP

<?php
namespace App\Http\Requests\User;
use App\Enums\UserAccessLevel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateUserRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$userId = $this->route('user')?->id ?? $this->route('user');
return [
'name' => ['sometimes', 'required', 'string', 'max:255'],
'username' => [
'nullable',
'string',
'max:255',
Rule::unique('users', 'username')->ignore($userId),
],
'email' => [
'sometimes',
'required',
'email',
'max:255',
Rule::unique('users', 'email')->ignore($userId),
],
'whatsapp_number' => ['nullable', 'string', 'max:20'],
'password' => ['nullable', 'string', 'min:8'],
'is_master' => ['nullable', 'boolean'],
'access_level' => ['sometimes', 'required', Rule::enum(UserAccessLevel::class)],
'status' => ['sometimes', 'required', Rule::in(['active', 'inactive', 'suspended'])],
'user_profile' => ['nullable', 'array'],
'user_profile.nik' => ['nullable', 'string', 'max:30'],
'user_profile.address' => ['nullable', 'string'],
'user_profile.provinsi_id' => ['nullable', 'integer', 'exists:wilayah_provinsi,id'],
'user_profile.kabupaten_id' => [
'nullable',
'integer',
Rule::exists('wilayah_kabupaten', 'id')->where(
'provinsi_id',
$this->input('user_profile.provinsi_id')
),
],
'user_profile.kecamatan_id' => [
'nullable',
'integer',
Rule::exists('wilayah_kecamatan', 'id')->where(
'kabupaten_id',
$this->input('user_profile.kabupaten_id')
),
],
'user_profile.desa_id' => [
'nullable',
'integer',
Rule::exists('wilayah_desa', 'id')->where(
'kecamatan_id',
$this->input('user_profile.kecamatan_id')
),
],
'user_tenants' => ['nullable', 'array'],
'user_tenants.*.tenant_id' => ['required_with:user_tenants', 'integer', 'exists:tenants,id'],
'user_tenants.*.is_default' => ['nullable', 'boolean'],
'user_menu_groups' => ['nullable', 'array'],
'user_menu_groups.*.menu_group_id' => ['required_with:user_menu_groups', 'integer', 'exists:menu_groups,id'],
'user_menu_groups.*.tenant_id' => ['nullable', 'integer', 'exists:tenants,id'],
];
}
}