Skip to content

Commit 380f0f2

Browse files
committed
Prevented a missing avatar from crashing the application
1 parent 33d4844 commit 380f0f2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/User.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,16 @@ public function hasSocialAccount($socialDriver = false)
160160
*/
161161
public function getAvatar($size = 50)
162162
{
163-
if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return baseUrl('/user_avatar.png');
164-
return baseUrl($this->avatar->getThumb($size, $size, false));
163+
$default = baseUrl('/user_avatar.png');
164+
$imageId = $this->image_id;
165+
if ($imageId === 0 || $imageId === '0' || $imageId === null) return $default;
166+
167+
try {
168+
$avatar = baseUrl($this->avatar->getThumb($size, $size, false));
169+
} catch (\Exception $err) {
170+
$avatar = $default;
171+
}
172+
return $avatar;
165173
}
166174

167175
/**

0 commit comments

Comments
 (0)