Skip to content

Commit 37e091a

Browse files
authored
Merge pull request #15889 from Godmartinz/Fix-user-API-location-update
Fixed Users API `update` from clearing `location_id` unnecessarily
2 parents 30b481b + 60642cd commit 37e091a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

app/Http/Controllers/Api/UsersController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,11 @@ public function update(SaveUserRequest $request, User $user): JsonResponse
480480
$user->permissions = $permissions_array;
481481
}
482482

483-
// Update the location of any assets checked out to this user
484-
Asset::where('assigned_type', User::class)
485-
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
486-
483+
if($request->has('location_id')) {
484+
// Update the location of any assets checked out to this user
485+
Asset::where('assigned_type', User::class)
486+
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
487+
}
487488
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
488489

489490
if ($user->save()) {

0 commit comments

Comments
 (0)