Skip to content

Commit 48ccc0e

Browse files
committed
Fix triggering a missing attribute violation
1 parent 50f0f48 commit 48ccc0e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Sentry/Laravel/EventHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,24 @@ private function configureUserScopeFromModel($authUser): void
274274

275275
// If the user is a Laravel Eloquent model we try to extract some common fields from it
276276
if ($authUser instanceof Model) {
277-
$username = $authUser->getAttribute('username');
277+
$email = null;
278+
279+
if ($authUser->hasAttribute('email')) {
280+
$email = $authUser->getAttribute('email');
281+
} elseif ($authUser->hasAttribute('mail')) {
282+
$email = $authUser->getAttribute('mail');
283+
}
284+
285+
$username = $authUser->hasAttribute('username')
286+
? (string)$authUser->getAttribute('username')
287+
: null;
278288

279289
$userData = [
280290
'id' => $authUser instanceof Authenticatable
281291
? $authUser->getAuthIdentifier()
282292
: $authUser->getKey(),
283-
'email' => $authUser->getAttribute('email') ?? $authUser->getAttribute('mail'),
284-
'username' => $username === null ? $username : (string)$username,
293+
'email' => $email,
294+
'username' => $username,
285295
];
286296
}
287297

0 commit comments

Comments
 (0)