diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 2338cebf750e..2987b2af5cda 100644 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -424,8 +424,12 @@ public function handle() $item['note'] = $item['createorupdate']; $item['status'] = 'success'; if ($item['createorupdate'] === 'created' && $ldap_default_group) { - $user->groups()->attach($ldap_default_group); + // Check if the relationship already exists + if (!$user->groups()->where('group_id', $ldap_default_group)->exists()) { + $user->groups()->attach($ldap_default_group); + } } + //updates assets location based on user's location Asset::where('assigned_to', '=', $user->id)->update(['location_id' => $user->location_id]);