From 2e8fb762ae99c65e2ae9c15bbffe3f5ca4e435c4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 15 Aug 2018 18:21:42 -0600 Subject: [PATCH] Update Profile model, improve #381 --- app/Profile.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Profile.php b/app/Profile.php index 4357684dc..c620582b1 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -125,14 +125,16 @@ class Profile extends Model public function avatar() { - return $this->hasOne(Avatar::class); + return $this->hasOne(Avatar::class)->withDefault([ + 'media_path' => 'public/avatars/default.png' + ]); } public function avatarUrl() { $url = Cache::remember("avatar:{$this->id}", 1440, function() { - $path = $this->avatar->media_path ?? 'public/avatars/default.png'; - $version = $this->avatar ? hash('sha1', $this->avatar->created_at) : ''; + $path = optional($this->avatar)->media_path; + $version = hash('sha1', $this->avatar->created_at); $path = "{$path}?v={$version}"; return url(Storage::url($path)); });