Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/Http/Controllers/Api/V1/UserApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function update(Request $request, $id): JsonResponse
$validator = Validator::make($request->all(), [
'password' => [
'sometimes',
'required',
'nullable',
Copy link

@cubic-dev-ai cubic-dev-ai bot Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the password rule to nullable doesn’t let an empty string through—min:8 and the regex still run on "", so the update request with "password": "" will keep failing validation. Please also skip the other rules when the value is empty (e.g. convert the empty string to null or add an exclude_if rule) so the intended case succeeds.

Prompt for AI agents
Address the following comment on app/Http/Controllers/Api/V1/UserApiController.php at line 135:

<comment>Switching the password rule to nullable doesn’t let an empty string through—`min:8` and the regex still run on &quot;&quot;, so the update request with `&quot;password&quot;: &quot;&quot;` will keep failing validation. Please also skip the other rules when the value is empty (e.g. convert the empty string to null or add an `exclude_if` rule) so the intended case succeeds.</comment>

<file context>
@@ -132,7 +132,7 @@ public function update(Request $request, $id): JsonResponse
             &#39;password&#39; =&gt; [
                 &#39;sometimes&#39;,
-                &#39;required&#39;,
+                &#39;nullable&#39;,
                 &#39;string&#39;,
                 &#39;min:8&#39;,
</file context>
Fix with Cubic

'string',
'min:8',
'max:255',
Expand All @@ -145,6 +145,13 @@ public function update(Request $request, $id): JsonResponse
'min:2',
'max:255'
],
'phone' => [
'sometimes',
'required',
'string',
'regex:/^\+?[\d\s\-\(\)]+$/',
'max:20'
],
'phone_number' => [
'sometimes',
'required',
Expand All @@ -165,11 +172,12 @@ public function update(Request $request, $id): JsonResponse
'exists:auto_dealerships,id'
]
], [
'password.required' => 'Пароль обязателен',
'password.min' => 'Пароль должен содержать минимум 8 символов',
'password.regex' => 'Пароль должен содержать минимум одну заглавную букву, одну строчную букву и одну цифру',
'full_name.required' => 'Полное имя обязательно',
'full_name.min' => 'Полное имя должно содержать минимум 2 символа',
'phone.required' => 'Телефон обязателен',
'phone.regex' => 'Некорректный формат телефона',
'phone_number.required' => 'Телефон обязателен',
'phone_number.regex' => 'Некорректный формат телефона',
'role.required' => 'Роль обязательна',
Expand All @@ -190,15 +198,19 @@ public function update(Request $request, $id): JsonResponse
try {
$updateData = [];

if (isset($validated['password'])) {
// Only update password if it's provided and not empty
if (isset($validated['password']) && $validated['password'] !== '' && $validated['password'] !== null) {
$updateData['password'] = Hash::make($validated['password']);
}

if (isset($validated['full_name'])) {
$updateData['full_name'] = $validated['full_name'];
}

if (isset($validated['phone_number'])) {
// Support both 'phone' and 'phone_number' fields
if (isset($validated['phone'])) {
$updateData['phone'] = $validated['phone'];
} elseif (isset($validated['phone_number'])) {
$updateData['phone'] = $validated['phone_number'];
}

Expand Down