- $emailHash = md5(strtolower(trim($this->email)));
- return '//www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon';
+ if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return '/user_avatar.png';
+ return $this->avatar->getThumb($size, $size, false);
+ }
+
+ /**
+ * 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 '/settings/users/' . $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 '';