+ $default = baseUrl('/user_avatar.png');
+ $imageId = $this->image_id;
+ if ($imageId === 0 || $imageId === '0' || $imageId === null) return $default;
+
+ try {
+ $avatar = $this->avatar ? baseUrl($this->avatar->getThumb($size, $size, false)) : $default;
+ } catch (\Exception $err) {
+ $avatar = $default;
+ }
+ return $avatar;
+ }
+
+ /**
+ * Get the avatar for the user.
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function avatar()
+ {
+ return $this->belongsTo(Image::class, 'image_id');
+ }
+
+ /**
+ * Get the url for editing this user.
+ * @return string
+ */
+ public function getEditUrl()
+ {
+ return baseUrl('/settings/users/' . $this->id);
+ }
+
+ /**
+ * Get the url that links to this user's profile.
+ * @return mixed
+ */
+ public function getProfileUrl()
+ {
+ return baseUrl('/user/' . $this->id);
+ }
+
+ /**
+ * Get a shortened version of the user's name.
+ * @param int $chars
+ * @return string
+ */
+ public function getShortName($chars = 8)
+ {
+ if (strlen($this->name) <= $chars) return $this->name;
+
+ $splitName = explode(' ', $this->name);
+ if (strlen($splitName[0]) <= $chars) return $splitName[0];
+
+ return '';
+ }
+
+ /**
+ * Send the password reset notification.
+ * @param string $token
+ * @return void
+ */
+ public function sendPasswordResetNotification($token)
+ {
+ $this->notify(new ResetPassword($token));