From bdc8ec77f04f2a3f535e462fed505366d562862d Mon Sep 17 00:00:00 2001 From: Jeroen Smeets Date: Wed, 15 Aug 2018 09:51:01 +0200 Subject: [PATCH 1/2] prevent crash when avatar not set on fresh install --- app/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Profile.php b/app/Profile.php index b1b73abf6..4357684dc 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -132,7 +132,7 @@ class Profile extends Model { $url = Cache::remember("avatar:{$this->id}", 1440, function() { $path = $this->avatar->media_path ?? 'public/avatars/default.png'; - $version = hash('sha1', $this->avatar->created_at); + $version = $this->avatar ? hash('sha1', $this->avatar->created_at) : ''; $path = "{$path}?v={$version}"; return url(Storage::url($path)); }); From 2e8fb762ae99c65e2ae9c15bbffe3f5ca4e435c4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 15 Aug 2018 18:21:42 -0600 Subject: [PATCH 2/2] 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)); });