Skip to content

Commit 79cdda5

Browse files
[6.x] Fix Eloquent user merge setting roles and groups as model attributes (#14526)
1 parent d9cf66e commit 79cdda5

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/Auth/Eloquent/User.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ public function remove($key)
303303

304304
public function merge($data)
305305
{
306-
$this->data($this->data()->merge(collect($data)->filter(fn ($v) => $v !== null)->all()));
306+
$merged = $this->data()
307+
->except(['roles', 'groups'])
308+
->merge(collect($data)->filter(fn ($v) => $v !== null)->all());
309+
310+
$this->data($merged->all());
307311

308312
return $this;
309313
}

tests/Auth/Eloquent/EloquentUserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,20 @@ public function it_does_not_save_null_values_on_the_model()
335335
$this->assertFalse($attributes['not_null_field']);
336336
}
337337

338+
#[Test]
339+
public function merge_does_not_set_roles_and_groups_as_model_attributes()
340+
{
341+
$user = $this->user();
342+
343+
$user->merge(['name' => 'Updated Name']);
344+
345+
$attributes = $user->model()->getAttributes();
346+
347+
$this->assertArrayNotHasKey('roles', $attributes);
348+
$this->assertArrayNotHasKey('groups', $attributes);
349+
$this->assertEquals('Updated Name', $attributes['name']);
350+
}
351+
338352
#[Test]
339353
#[Group('passkeys')]
340354
public function it_gets_passkeys()

0 commit comments

Comments
 (0)